diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e588f4d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake + +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0'] + + steps: + - name: Check out repository code + uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run tests + run: bundle exec rake diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml deleted file mode 100644 index e26f6ed..0000000 --- a/.github/workflows/ruby.yml +++ /dev/null @@ -1,35 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake -# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby - -name: Ruby - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - test: - - runs-on: ubuntu-latest - strategy: - matrix: - ruby-version: ['2.6', '2.7', '3.0'] - - steps: - - uses: actions/checkout@v2 - - name: Set up Ruby - # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, - # change this to (see https://github.com/ruby/setup-ruby#versioning): - # uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - name: Run tests - run: bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 485f9b4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -language: ruby -cache: bundler -rvm: - - 2.7.2 -before_install: gem install bundler -v 1.17.3 diff --git a/CHANGELOG.md b/CHANGELOG.md index f00789c..b3052d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,12 @@ +## 0.2.2 2021-10-09 + +**Changes** + 1. After adding GitHub actions, I discovered that the gem did not in fact work on all the versions of Ruby that I had thought it supported. This update makes some small tweaks to bring support to Ruby 2.4 then updates the `.gemspec` to clarify that 2.3 is not in fact supported. All current users of the gem should see no behavior changes as a result of this update 👍🏻 + ## 0.2.1 2021-10-07 **Changes** - 1. Simplifying the errors returned from `Pcloud::Folder` and `Pcloud::File`. This is purely a cleanup release, unless your client is explicitly checking error strings there should be no noticeable behavior change 👍🏻 + 1. Simplifying the errors returned from `Pcloud::Folder` and `Pcloud::File`. This is purely a cleanup release, unless your client is explicitly checking error strings there should be no noticeable behavior change 👍🏻 ## 0.2.0 2021-10-07 diff --git a/README.md b/README.md index 84ce98f..5229c36 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # pCloud API +[![CI](https://github.com/jhunschejones/pcloud_api/actions/workflows/ci.yml/badge.svg)](https://github.com/jhunschejones/pcloud_api/actions/workflows/ci.yml) + The `pcloud_api` gem provides an intuitive Ruby interface for interacting with the [pCloud API](https://docs.pcloud.com/) using OAuth2. This gem does not attempt to replicate the entire functionality of the pCloud API but rather to provide quick and easy access for its most basic and common functionality. If you are looking for a lower-level pCloud API wrapper, [`pcloud`](https://github.com/7urkm3n/pcloud) might be a better fit for you. ## Installation @@ -18,6 +20,12 @@ Or install it yourself as: $ gem install pcloud_api +## Requirements + +* Ruby 2.4.0 or higher +* `httparty` +* `tzinfo` + ## Usage ### Configuration @@ -41,16 +49,21 @@ The `Pcloud::File` API includes: # Find files by file id or path: Pcloud::File.find(1) Pcloud::File.find_by(path: "/images/jack_the_cat.jpg") +# NOTE: find_by can also be used with :id, though this will take precedence +# over :path so just pick one or the other -# Upload a new file, rename if already existing: +# Check if a file exists by id +Pcloud::File.exists?(1) + +# Upload a new file, rename if one already exists with this name: Pcloud::File.upload( folder_id: 1, filename: "jack_goes_swimming.mp4", file: File.open("/Users/joshua/Downloads/jack_goes_swimming.mp4") ) -# NOTE: the upload method will allow you to specify either the `path` or the -# `folder_id`, or you can choose to pass neither paramenter and your files will -# be placed in your root pCloud directory. +# NOTE: the upload method will allow you to specify the :path or the :folder_id +# or you can choose to pass neither paramenter and your files will be placed +# in your root pCloud directory. # Upload a file, force overwrite of existing file: Pcloud::File.upload!( @@ -80,6 +93,11 @@ The `Pcloud::Folder` API is very similar: # Find folders by folder id or path: Pcloud::Folder.find(1) Pcloud::Folder.find_by(path: "/images") +# NOTE: find_by can also be used with :id, though this will take precedence +# over :path so just pick one or the other + +# Check if a folder exists by id +Pcloud::Folder.exists?(1) # Create a new folder by parent_folder_id and name: Pcloud::Folder.first_or_create(parent_folder_id: 9000, name: "jack") diff --git a/lib/pcloud/time_helper.rb b/lib/pcloud/time_helper.rb index 3a2123c..ec1d99f 100644 --- a/lib/pcloud/time_helper.rb +++ b/lib/pcloud/time_helper.rb @@ -14,7 +14,9 @@ def time_from(time) return Time.at(time) if time.digits.size < 13 milliseconds = time.to_s[-3..-1].to_i seconds = time.to_s[0..-4].to_i - Time.at(seconds, milliseconds, :millisecond) + # Older Ruby versions only support microseconds as the second + # argument to Time.at/2 + Time.at(seconds, milliseconds * 1000) elsif time.is_a?(Time) time else diff --git a/lib/pcloud/version.rb b/lib/pcloud/version.rb index 8b13cee..8ae6dcc 100644 --- a/lib/pcloud/version.rb +++ b/lib/pcloud/version.rb @@ -1,3 +1,3 @@ module Pcloud - VERSION = "0.2.1" + VERSION = "0.2.2" end diff --git a/pcloud_api.gemspec b/pcloud_api.gemspec index 20f5504..fc2dc9b 100644 --- a/pcloud_api.gemspec +++ b/pcloud_api.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.summary = "A Ruby library for interacting with the pCloud API" spec.homepage = "https://github.com/jhunschejones/pcloud_api" spec.license = "MIT" - spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") + spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0") spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/jhunschejones/pcloud_api" @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.github)/}) } end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } diff --git a/spec/pcloud/time_helper_spec.rb b/spec/pcloud/time_helper_spec.rb index b9d28db..9580d11 100644 --- a/spec/pcloud/time_helper_spec.rb +++ b/spec/pcloud/time_helper_spec.rb @@ -3,6 +3,17 @@ class TestClass include Pcloud::TimeHelper end + # This method does not exist before Ruby 2.7. I'm adding it here so that the + # test suite will work on older Ruby's. (The gem's code itself does not + # depend on this method existing.) + unless Time.method_defined? :floor + class Time + def floor(floor=0) + Time.at(self.to_r.floor(floor)) + end + end + end + let(:subject) { TestClass.new } let(:time) { Time.now } @@ -12,7 +23,7 @@ class TestClass end it "parses a time object" do - expect(subject.send(:time_from, time)).to eq(time.utc.floor(6)) + expect(subject.send(:time_from, time)).to eq(time.utc) end it "parses a string timestamp" do @@ -34,7 +45,6 @@ class TestClass expected_local_timezone_time = TZInfo::Timezone .get("America/Los_Angeles") .to_local(time) - .floor(6) # includes milliseconds expect(subject.send(:time_from, time)).to eq(expected_local_timezone_time) end