Skip to content

Commit

Permalink
Add older Ruby support + update GitHub actions (#6)
Browse files Browse the repository at this point in the history
* Update documentation

* Fix failing tests (rounding errors)

* Add missing method for older Ruby versions

* Additional change to bring support back to Ruby 2.4

* Prepare for 0.2.2 release

* Rename workflow and add badge

* Rename and clean up GitHub action, add requirements to README

* Update status badge

* Don't bundle CI directory with gem

* Delete .travis.yml
  • Loading branch information
jhunschejones authored Oct 9, 2021
1 parent 48a0840 commit da464f4
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 52 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 0 additions & 35 deletions .github/workflows/ruby.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,6 +20,12 @@ Or install it yourself as:

$ gem install pcloud_api

## Requirements

* Ruby 2.4.0 or higher
* `httparty`
* `tzinfo`

## Usage

### Configuration
Expand All @@ -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!(
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion lib/pcloud/time_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pcloud/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Pcloud
VERSION = "0.2.1"
VERSION = "0.2.2"
end
4 changes: 2 additions & 2 deletions pcloud_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) }
Expand Down
14 changes: 12 additions & 2 deletions spec/pcloud/time_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit da464f4

Please sign in to comment.