pocket-ruby 0.0.7 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3122a98c3cb3376028f8a462592c41319644c8cc90a93fa6d8ff4e87b791eeac
4
- data.tar.gz: fb0332aba6196f4fda5fbca81852b8f2d41e60ef4c1e01ee4b606cf6c3616700
3
+ metadata.gz: 23523be975e32aab67f1eb9eae5bd8a9a23032e7b9e32dd16c7ebd54829dcfd5
4
+ data.tar.gz: f340f0180bffcee80c64321392205ad43439434a12171b670baab1b7c30eb56f
5
5
  SHA512:
6
- metadata.gz: 503a272080aae025c43fb483afe97754520d57e6d7ce36f32496a134e67a48a6eb86ef485f3461b7724d79b4904bc20eebd283266791c8a2c339a09c4ea44335
7
- data.tar.gz: 0b6710b2060d3371575b3b06761f51b27835b604167adf56a4ff0eb8050eb6c5b6d97a63b9579ef6864e6a2733fe810012e701bcd3c02f7ebc173e502cec68a3
6
+ metadata.gz: 9c639bdd2f2637e55642da60be20d03e3e8e4ea7bc87b2da4ebf5951d8f99d7717e3d7608e3ec66c79a1e7b0bdf49f4c673a95590ffa34bd54baf4f0b5293b8a
7
+ data.tar.gz: 03f454e5471e90266dce757748b7a3fefad8adcfefd954bae3e2bd52f687dc922c7d0d7911ef02e85b94344f733803b6aea2c5dbfb50dfe45c2a0f8679ed81e0
@@ -0,0 +1,19 @@
1
+ name: changelog-checker
2
+ on:
3
+ pull_request:
4
+ types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
5
+ branches:
6
+ - master
7
+ jobs:
8
+ build:
9
+ name: Check Actions
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v1
13
+ - name: Changelog check
14
+ uses: Zomzog/changelog-checker@v1.2.0
15
+ with:
16
+ fileName: CHANGELOG.md
17
+ checksNotification: Simple
18
+ env:
19
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.6.6
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -11,7 +11,6 @@ spec/reports
11
11
  test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
- Gemfile.lock
15
14
  # YARD artifacts
16
15
  .yardoc
17
16
  _yardoc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.1] - 2021-04-10
4
+
5
+ - Return nil if `time_read` or `time_favorited` is '0' in the API response. Otherwise, this may be interpreted the Unix epoch (1970-01-01). ([#46](https://github.com/turadg/pocket-ruby/pull/46))
6
+
7
+ ## [0.2.0] - 2021-04-03
8
+
9
+ - Add support for authors and tags in `Pocket::Article` ([#44](https://github.com/turadg/pocket-ruby/pull/44))
10
+
11
+ ## [0.1.0] - 2021-04-03
12
+
13
+ - Add `Pocket::Article` for parsing an article response ([#39](https://github.com/turadg/pocket-ruby/pull/39))
14
+ - Fix Pocket::Client::Retrieve#retrieve params default ([#21](https://github.com/turadg/pocket-ruby/pull/21))
15
+
16
+ ## [0.0.9] - 2021-04-01
17
+
18
+ - Actually remove unused Hashie dependency ([#35](https://github.com/turadg/pocket-ruby/pull/35))
19
+
20
+ ## [0.0.8] - 2021-03-31
21
+
22
+ - Fix Ruby warnings ([#32](https://github.com/turadg/pocket-ruby/pull/32))
23
+ - Remove unused Hashie dependency ([#31](https://github.com/turadg/pocket-ruby/pull/31))
24
+
3
25
  ## [0.0.7] - 2021-03-29
4
26
 
5
27
  - Relax `faraday_middleware` version constraint ([#25](https://github.com/turadg/pocket-ruby/pull/25))
data/Gemfile.lock ADDED
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pocket-ruby (0.2.1)
5
+ faraday (>= 0.7)
6
+ faraday_middleware
7
+ multi_json (~> 1.0, >= 1.0.3)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ docile (1.3.5)
14
+ faraday (1.3.0)
15
+ faraday-net_http (~> 1.0)
16
+ multipart-post (>= 1.2, < 3)
17
+ ruby2_keywords
18
+ faraday-net_http (1.0.1)
19
+ faraday_middleware (1.0.0)
20
+ faraday (~> 1.0)
21
+ multi_json (1.15.0)
22
+ multi_xml (0.6.0)
23
+ multipart-post (2.1.1)
24
+ parallel (1.20.1)
25
+ parser (3.0.0.0)
26
+ ast (~> 2.4.1)
27
+ power_assert (2.0.0)
28
+ rack (1.6.13)
29
+ rack-protection (1.5.5)
30
+ rack
31
+ rainbow (3.0.0)
32
+ rake (13.0.3)
33
+ regexp_parser (2.1.1)
34
+ rexml (3.2.4)
35
+ rubocop (1.11.0)
36
+ parallel (~> 1.10)
37
+ parser (>= 3.0.0.0)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ regexp_parser (>= 1.8, < 3.0)
40
+ rexml
41
+ rubocop-ast (>= 1.2.0, < 2.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 1.4.0, < 3.0)
44
+ rubocop-ast (1.4.1)
45
+ parser (>= 2.7.1.5)
46
+ rubocop-performance (1.10.1)
47
+ rubocop (>= 0.90.0, < 2.0)
48
+ rubocop-ast (>= 0.4.0)
49
+ ruby-progressbar (1.11.0)
50
+ ruby2_keywords (0.0.4)
51
+ simplecov (0.21.2)
52
+ docile (~> 1.1)
53
+ simplecov-html (~> 0.11)
54
+ simplecov_json_formatter (~> 0.1)
55
+ simplecov-html (0.12.3)
56
+ simplecov_json_formatter (0.1.2)
57
+ sinatra (1.3.6)
58
+ rack (~> 1.4)
59
+ rack-protection (~> 1.3)
60
+ tilt (~> 1.3, >= 1.3.3)
61
+ standard (1.0.4)
62
+ rubocop (= 1.11.0)
63
+ rubocop-performance (= 1.10.1)
64
+ test-unit (3.4.0)
65
+ power_assert
66
+ tilt (1.4.1)
67
+ unicode-display_width (2.0.0)
68
+
69
+ PLATFORMS
70
+ x86_64-darwin-19
71
+ x86_64-linux
72
+
73
+ DEPENDENCIES
74
+ multi_xml
75
+ pocket-ruby!
76
+ rake
77
+ simplecov
78
+ sinatra (~> 1.3.3)
79
+ standard
80
+ test-unit
81
+
82
+ BUNDLED WITH
83
+ 2.2.8
data/README.md CHANGED
@@ -19,13 +19,3 @@ Just clone the repo here and refer to the demo-server.rb file for examples on ho
19
19
  Pocket-Ruby can be installed via the gem, ```gem install pocket-ruby```
20
20
 
21
21
  Or via bundler, ```gem 'pocket-ruby'```
22
-
23
- # For v0.0.5 and earlier
24
-
25
- Using v0.0.5 and earlier may result in a ```require``` error. To fix this you may either update to a newer version of the gem or uninstall with ```gem uninstall pocket-ruby``` and try again using the method below:
26
-
27
- Install via the gem, ```gem install pocket-ruby -v 0.0.5```
28
-
29
- Or via bundler, ```gem 'pocket-ruby', '0.0.5', :require => 'pocket'```
30
-
31
- Be sure to require the gem in your code with ```require 'pocket'``` not ```require 'pocket-ruby'```
data/Rakefile CHANGED
@@ -1,27 +1,31 @@
1
- require 'bundler'
1
+ require "bundler"
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
4
+ require "standard/rake"
6
5
 
7
- task :default => :spec
6
+ require "rake/testtask"
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.libs << "lib"
10
+ t.test_files = FileList["test/**/*_test.rb"]
11
+ end
12
+
13
+ task default: [:test, :standard]
8
14
 
9
15
  namespace :doc do
10
- begin
11
- require 'yard'
12
- rescue LoadError
13
- # ignore
14
- else
15
- YARD::Rake::YardocTask.new do |task|
16
- task.files = ['HISTORY.mkd', 'LICENSE.mkd', 'lib/**/*.rb']
17
- task.options = [
18
- '--protected',
19
- '--output-dir', 'doc/yard',
20
- '--tag', 'format:Supported formats',
21
- '--tag', 'authenticated:Requires Authentication',
22
- '--tag', 'rate_limited:Rate Limited',
23
- '--markup', 'markdown',
24
- ]
25
- end
16
+ require "yard"
17
+ rescue LoadError
18
+ # ignore
19
+ else
20
+ YARD::Rake::YardocTask.new do |task|
21
+ task.files = ["HISTORY.mkd", "LICENSE.mkd", "lib/**/*.rb"]
22
+ task.options = [
23
+ "--protected",
24
+ "--output-dir", "doc/yard",
25
+ "--tag", "format:Supported formats",
26
+ "--tag", "authenticated:Requires Authentication",
27
+ "--tag", "rate_limited:Rate Limited",
28
+ "--markup", "markdown"
29
+ ]
26
30
  end
27
31
  end
data/demo-server.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  require "sinatra"
2
2
 
3
- require "./lib/pocket-ruby.rb"
3
+ require "./lib/pocket-ruby"
4
4
 
5
5
  enable :sessions
6
6
 
7
7
  CALLBACK_URL = "http://localhost:4567/oauth/callback"
8
8
 
9
9
  Pocket.configure do |config|
10
- config.consumer_key = '10188-3565cd04d1464e6d0e64b67f'
10
+ config.consumer_key = "10188-3565cd04d1464e6d0e64b67f"
11
11
  end
12
12
 
13
- get '/reset' do
13
+ get "/reset" do
14
14
  puts "GET /reset"
15
15
  session.clear
16
16
  end
@@ -31,8 +31,8 @@ end
31
31
 
32
32
  get "/oauth/connect" do
33
33
  puts "OAUTH CONNECT"
34
- session[:code] = Pocket.get_code(:redirect_uri => CALLBACK_URL)
35
- new_url = Pocket.authorize_url(:code => session[:code], :redirect_uri => CALLBACK_URL)
34
+ session[:code] = Pocket.get_code(redirect_uri: CALLBACK_URL)
35
+ new_url = Pocket.authorize_url(code: session[:code], redirect_uri: CALLBACK_URL)
36
36
  puts "new_url: #{new_url}"
37
37
  puts "session: #{session}"
38
38
  redirect new_url
@@ -42,26 +42,26 @@ get "/oauth/callback" do
42
42
  puts "OAUTH CALLBACK"
43
43
  puts "request.url: #{request.url}"
44
44
  puts "request.body: #{request.body.read}"
45
- result = Pocket.get_result(session[:code], :redirect_uri => CALLBACK_URL)
46
- session[:access_token] = result['access_token']
47
- puts result['access_token']
48
- puts result['username']
45
+ result = Pocket.get_result(session[:code], redirect_uri: CALLBACK_URL)
46
+ session[:access_token] = result["access_token"]
47
+ puts result["access_token"]
48
+ puts result["username"]
49
49
  # Alternative method to get the access token directly
50
- #session[:access_token] = Pocket.get_access_token(session[:code])
50
+ # session[:access_token] = Pocket.get_access_token(session[:code])
51
51
  puts session[:access_token]
52
52
  puts "session: #{session}"
53
53
  redirect "/"
54
54
  end
55
55
 
56
- get '/add' do
57
- client = Pocket.client(:access_token => session[:access_token])
58
- info = client.add :url => 'http://getpocket.com'
56
+ get "/add" do
57
+ client = Pocket.client(access_token: session[:access_token])
58
+ info = client.add url: "http://getpocket.com"
59
59
  "<pre>#{info}</pre>"
60
60
  end
61
61
 
62
62
  get "/retrieve" do
63
- client = Pocket.client(:access_token => session[:access_token])
64
- info = client.retrieve(:detailType => :complete, :count => 1)
63
+ client = Pocket.client(access_token: session[:access_token])
64
+ info = client.retrieve(detailType: :complete, count: 1)
65
65
 
66
66
  # html = "<h1>#{user.username}'s recent photos</h1>"
67
67
  # for media_item in client.user_recent_media
@@ -1,4 +1,4 @@
1
- require 'faraday'
1
+ require "faraday"
2
2
 
3
3
  # @private
4
4
  module FaradayMiddleware
@@ -6,16 +6,16 @@ module FaradayMiddleware
6
6
  class PocketOAuth < Faraday::Middleware
7
7
  def call(env)
8
8
  env[:body] = {} if env[:body].nil?
9
- env[:body] = env[:body].merge(:consumer_key => @consumer_key)
9
+ env[:body] = env[:body].merge(consumer_key: @consumer_key)
10
10
 
11
11
  if @access_token
12
- env[:body] = env[:body].merge(:access_token => @access_token)
12
+ env[:body] = env[:body].merge(access_token: @access_token)
13
13
  end
14
14
 
15
15
  @app.call env
16
16
  end
17
17
 
18
- def initialize(app, consumer_key, access_token=nil)
18
+ def initialize(app, consumer_key, access_token = nil)
19
19
  @app = app
20
20
  @consumer_key = consumer_key
21
21
  @access_token = access_token
@@ -1,5 +1,4 @@
1
1
  module Faraday
2
-
3
2
  # HTTP Status X-Error-Code X-Error
4
3
  # 400 138 Missing consumer key.
5
4
  # 403 152 Invalid consumer key.
@@ -9,24 +8,24 @@ module Faraday
9
8
  # 403 158 User rejected code.
10
9
  # 403 159 Already used code.
11
10
  # 50X 199 Pocket server issue.
12
- #
11
+ #
13
12
  # @see http://getpocket.com/developer/docs/authentication
14
13
  class Response::RaisePocketError < Response::Middleware
15
- ClientErrorStatuses = 400...600
14
+ CLIENT_ERROR_STATUSES = 400...600
16
15
 
17
16
  def on_complete(env)
18
17
  case env[:status]
19
18
  when 404
20
19
  raise Faraday::Error::ResourceNotFound, response_values(env)
21
20
  when 400...403
22
- raise Pocket::Error, env[:response_headers]['X-Error']
23
- when ClientErrorStatuses
21
+ raise Pocket::Error, env[:response_headers]["X-Error"]
22
+ when CLIENT_ERROR_STATUSES
24
23
  raise Faraday::Error::ClientError, response_values(env)
25
24
  end
26
25
  end
27
26
 
28
27
  def response_values(env)
29
- {:status => env[:status], :headers => env[:response_headers], :body => env[:body]}
28
+ {status: env[:status], headers: env[:response_headers], body: env[:body]}
30
29
  end
31
30
  end
32
31
  end
data/lib/pocket-ruby.rb CHANGED
@@ -1,7 +1,9 @@
1
- require File.expand_path('../pocket/error', __FILE__)
2
- require File.expand_path('../pocket/configuration', __FILE__)
3
- require File.expand_path('../pocket/api', __FILE__)
4
- require File.expand_path('../pocket/client', __FILE__)
1
+ require File.expand_path("../pocket/error", __FILE__)
2
+ require File.expand_path("../pocket/configuration", __FILE__)
3
+ require File.expand_path("../pocket/api", __FILE__)
4
+ require File.expand_path("../pocket/client", __FILE__)
5
+ require File.expand_path("../pocket/article", __FILE__)
6
+ require File.expand_path("../pocket/author", __FILE__)
5
7
 
6
8
  module Pocket
7
9
  extend Configuration
@@ -9,7 +11,7 @@ module Pocket
9
11
  # Alias for Pocket::Client.new
10
12
  #
11
13
  # @return [Pocket::Client]
12
- def self.client(options={})
14
+ def self.client(options = {})
13
15
  Pocket::Client.new(options)
14
16
  end
15
17
 
@@ -20,7 +22,7 @@ module Pocket
20
22
  end
21
23
 
22
24
  # Delegate to Pocket::Client
23
- def self.respond_to?(method)
24
- return client.respond_to?(method) || super
25
+ def self.respond_to_missing?(method)
26
+ client.respond_to?(method) || super
25
27
  end
26
28
  end
data/lib/pocket/api.rb CHANGED
@@ -1,14 +1,14 @@
1
- require File.expand_path('../connection', __FILE__)
2
- require File.expand_path('../oauth', __FILE__)
1
+ require File.expand_path("../connection", __FILE__)
2
+ require File.expand_path("../oauth", __FILE__)
3
3
 
4
4
  module Pocket
5
5
  # @private
6
6
  class API
7
7
  # @private
8
- attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
9
9
 
10
10
  # Creates a new API
11
- def initialize(options={})
11
+ def initialize(options = {})
12
12
  options = Pocket.options.merge(options)
13
13
  Configuration::VALID_OPTIONS_KEYS.each do |key|
14
14
  send("#{key}=", options[key])
@@ -0,0 +1,121 @@
1
+ require "json"
2
+
3
+ module Pocket
4
+ class Article
5
+ attr_reader :response
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def self.from_json(json_string)
12
+ new(JSON.parse(json_string))
13
+ end
14
+
15
+ def item_id
16
+ Integer(response.fetch("item_id"))
17
+ end
18
+
19
+ def given_url
20
+ response.fetch("given_url")
21
+ end
22
+
23
+ def resolved_url
24
+ response.fetch("resolved_url")
25
+ end
26
+
27
+ def given_title
28
+ response.fetch("given_title")
29
+ end
30
+
31
+ def resolved_title
32
+ response.fetch("resolved_title")
33
+ end
34
+
35
+ def favorite?
36
+ Integer(response.fetch("favorite")) == 1
37
+ end
38
+
39
+ def status
40
+ Integer(response.fetch("status"))
41
+ end
42
+
43
+ def excerpt
44
+ response.fetch("excerpt")
45
+ end
46
+
47
+ def article?
48
+ Integer(response.fetch("is_article")) == 1
49
+ end
50
+
51
+ def has_image?
52
+ Integer(response.fetch("has_image")) == 1
53
+ end
54
+
55
+ def image?
56
+ Integer(response.fetch("has_image")) == 2
57
+ end
58
+
59
+ def has_video?
60
+ Integer(response.fetch("has_video")) == 1
61
+ end
62
+
63
+ def video?
64
+ Integer(response.fetch("has_video")) == 2
65
+ end
66
+
67
+ def word_count
68
+ Integer(response.fetch("word_count"))
69
+ end
70
+
71
+ def resolved_id
72
+ Integer(response.fetch("resolved_id"))
73
+ end
74
+
75
+ def thumbnail
76
+ response.fetch("top_image_url", "")
77
+ end
78
+
79
+ def time_added
80
+ return nil unless response["time_added"]
81
+ Time.at(Integer(response["time_added"])).utc
82
+ end
83
+
84
+ def time_updated
85
+ return nil unless response["time_updated"]
86
+ Time.at(Integer(response["time_updated"])).utc
87
+ end
88
+
89
+ def time_read
90
+ return nil unless response["time_read"]
91
+ return nil if response["time_read"] == "0"
92
+ Time.at(Integer(response["time_read"])).utc
93
+ end
94
+
95
+ def favorited?
96
+ Integer(response["time_favorited"]) > 0
97
+ end
98
+
99
+ def time_favorited
100
+ return nil unless response["time_favorited"]
101
+ return nil if response["time_favorited"] == "0"
102
+ Time.at(Integer(response["time_favorited"])).utc
103
+ end
104
+
105
+ def read?
106
+ Integer(response["time_read"]) > 0
107
+ end
108
+
109
+ def read_url
110
+ "https://getpocket.com/read/#{item_id}"
111
+ end
112
+
113
+ def tags
114
+ Hash(response["tags"]).values.map { |tag| tag["tag"] }
115
+ end
116
+
117
+ def authors
118
+ Hash(response["authors"]).values.map { |value| Pocket::Author.new(value) }
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,23 @@
1
+ module Pocket
2
+ class Author
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ def id
8
+ Integer(response.fetch("author_id"))
9
+ end
10
+
11
+ def name
12
+ response.fetch("name")
13
+ end
14
+
15
+ def url
16
+ response.fetch("url")
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :response
22
+ end
23
+ end
data/lib/pocket/client.rb CHANGED
@@ -4,7 +4,7 @@ module Pocket
4
4
  # @note All methods have been separated into modules and follow the same grouping used in {TODO:doc_URL the Pocket API Documentation}.
5
5
  # @see TODO:doc_url
6
6
  class Client < API
7
- Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
7
+ Dir[File.expand_path("../client/*.rb", __FILE__)].sort.each { |f| require f }
8
8
 
9
9
  include Pocket::Client::Add
10
10
  include Pocket::Client::Modify
@@ -3,7 +3,7 @@ module Pocket
3
3
  # http://getpocket.com/developer/docs/v3/retrieve
4
4
  module Retrieve
5
5
  # required params: consumer_key, access_token
6
- def retrieve params=[]
6
+ def retrieve params = {}
7
7
  response = connection.post("/v3/get", params)
8
8
  response.body
9
9
  end
@@ -1,5 +1,5 @@
1
- require 'faraday'
2
- require File.expand_path('../version', __FILE__)
1
+ require "faraday"
2
+ require File.expand_path("../version", __FILE__)
3
3
 
4
4
  module Pocket
5
5
  # Defines constants and methods related to configuration
@@ -20,7 +20,8 @@ module Pocket
20
20
  #
21
21
  # @note Not all methods support the XML format.
22
22
  VALID_FORMATS = [
23
- :json].freeze
23
+ :json
24
+ ].freeze
24
25
 
25
26
  # The adapter that will be used to connect if none is set
26
27
  #
@@ -39,7 +40,7 @@ module Pocket
39
40
  # The endpoint that will be used to connect if none is set
40
41
  #
41
42
  # @note There is no reason to use any other endpoint at this time
42
- DEFAULT_ENDPOINT = 'https://getpocket.com/v3/'.freeze
43
+ DEFAULT_ENDPOINT = "https://getpocket.com/v3/".freeze
43
44
 
44
45
  # The response format appended to the path and sent in the 'Accept' header if none is set
45
46
  #
@@ -53,7 +54,7 @@ module Pocket
53
54
  DEFAULT_USER_AGENT = "Pocket Ruby Gem #{Pocket::VERSION}".freeze
54
55
 
55
56
  # @private
56
- attr_accessor *VALID_OPTIONS_KEYS
57
+ attr_accessor(*VALID_OPTIONS_KEYS)
57
58
 
58
59
  # When this module is extended, set all configuration options to their default values
59
60
  def self.extended(base)
@@ -74,14 +75,14 @@ module Pocket
74
75
 
75
76
  # Reset all configuration options to defaults
76
77
  def reset
77
- self.adapter = DEFAULT_ADAPTER
78
- self.consumer_key = DEFAULT_CONSUMER_KEY
79
- self.access_token = DEFAULT_ACCESS_TOKEN
80
- self.endpoint = DEFAULT_ENDPOINT
81
- self.redirect_uri = DEFAULT_REDIRECT_URI
82
- self.format = DEFAULT_FORMAT
83
- self.user_agent = DEFAULT_USER_AGENT
84
- self.proxy = DEFAULT_PROXY
78
+ self.adapter = DEFAULT_ADAPTER
79
+ self.consumer_key = DEFAULT_CONSUMER_KEY
80
+ self.access_token = DEFAULT_ACCESS_TOKEN
81
+ self.endpoint = DEFAULT_ENDPOINT
82
+ self.redirect_uri = DEFAULT_REDIRECT_URI
83
+ self.format = DEFAULT_FORMAT
84
+ self.user_agent = DEFAULT_USER_AGENT
85
+ self.proxy = DEFAULT_PROXY
85
86
  end
86
87
  end
87
88
  end
@@ -1,17 +1,17 @@
1
- require 'faraday_middleware'
2
- Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
1
+ require "faraday_middleware"
2
+ Dir[File.expand_path("../../faraday/*.rb", __FILE__)].sort.each { |f| require f }
3
3
 
4
4
  module Pocket
5
5
  # @private
6
6
  module Connection
7
7
  private
8
8
 
9
- def connection(raw=false)
9
+ def connection(raw = false)
10
10
  options = {
11
- :headers => {'User-Agent' => user_agent},
12
- :proxy => proxy,
13
- :ssl => {:verify => false},
14
- :url => endpoint,
11
+ headers: {"User-Agent" => user_agent},
12
+ proxy: proxy,
13
+ ssl: {verify: false},
14
+ url: endpoint
15
15
  }
16
16
 
17
17
  Faraday::Connection.new(options) do |conn|
@@ -20,7 +20,7 @@ module Pocket
20
20
 
21
21
  conn.request :json
22
22
 
23
- conn.response :json, :content_type => /\bjson$/
23
+ conn.response :json, content_type: /\bjson$/
24
24
 
25
25
  conn.adapter Faraday.default_adapter
26
26
  end
data/lib/pocket/oauth.rb CHANGED
@@ -2,7 +2,7 @@ module Pocket
2
2
  # Defines HTTP request methods
3
3
  module OAuth
4
4
  # Return URL for OAuth authorization
5
- def authorize_url(options={})
5
+ def authorize_url(options = {})
6
6
  params = access_token_params.merge(options)
7
7
  params.delete(:consumer_key) # shouldn't be exposed publically
8
8
  # Pocket renames `code` to `request_token` for some reason in this call
@@ -11,34 +11,34 @@ module Pocket
11
11
  end
12
12
 
13
13
  # Return a Pocket code
14
- def get_code(options={})
14
+ def get_code(options = {})
15
15
  params = access_token_params.merge(options)
16
- response = connection.post 'oauth/request', params
16
+ response = connection.post "oauth/request", params
17
17
  results = Hash[URI.decode_www_form(response.body)]
18
- code = results['code']
18
+ results["code"]
19
19
  end
20
20
 
21
21
  # Return an access token from authorization
22
- def get_access_token(code, options={})
23
- params = access_token_params.merge(:code => code).merge(options)
24
- response = connection.post 'oauth/authorize', params
22
+ def get_access_token(code, options = {})
23
+ params = access_token_params.merge(code: code).merge(options)
24
+ response = connection.post "oauth/authorize", params
25
25
  results = Hash[URI.decode_www_form(response.body)]
26
- access_token = results['access_token']
26
+ results["access_token"]
27
27
  end
28
28
 
29
29
  # Return result from authorization
30
- def get_result(code, options={})
31
- params = access_token_params.merge(:code => code).merge(options)
32
- response = connection.post 'oauth/authorize', params
33
- results = Hash[URI.decode_www_form(response.body)]
30
+ def get_result(code, options = {})
31
+ params = access_token_params.merge(code: code).merge(options)
32
+ response = connection.post "oauth/authorize", params
33
+ Hash[URI.decode_www_form(response.body)]
34
34
  end
35
35
 
36
36
  private
37
37
 
38
38
  def access_token_params
39
39
  {
40
- :consumer_key => consumer_key,
41
- :redirect_uri => redirect_uri
40
+ consumer_key: consumer_key,
41
+ redirect_uri: redirect_uri
42
42
  }
43
43
  end
44
44
  end
@@ -1,3 +1,3 @@
1
1
  module Pocket
2
- VERSION = '0.0.7'
2
+ VERSION = "0.2.1"
3
3
  end
data/pocket-ruby.gemspec CHANGED
@@ -1,25 +1,27 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/pocket/version', __FILE__)
1
+ require File.expand_path("../lib/pocket/version", __FILE__)
3
2
 
4
3
  Gem::Specification.new do |s|
5
- s.add_development_dependency('sinatra', '~> 1.3.3')
6
- s.add_development_dependency('multi_xml')
7
- s.add_runtime_dependency('faraday', ['>= 0.7'])
8
- s.add_runtime_dependency('faraday_middleware')
9
- s.add_runtime_dependency('multi_json', '>= 1.0.3', '~> 1.0')
10
- s.add_runtime_dependency('hashie', '>= 0.4.0')
11
- s.authors = ["Turadg Aleahmad","Jason Ng PT"]
12
- s.description = %q{A Ruby wrapper for the Pocket API v3 (Add, Modify and Retrieve)}
13
- s.email = ['turadg@aleahmad.net',"me@jasonngpt.com"]
14
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
4
+ s.add_development_dependency("sinatra", "~> 1.3.3")
5
+ s.add_development_dependency("multi_xml")
6
+ s.add_development_dependency("rake")
7
+ s.add_development_dependency("standard")
8
+ s.add_development_dependency("test-unit")
9
+ s.add_development_dependency("simplecov")
10
+ s.add_runtime_dependency("faraday", [">= 0.7"])
11
+ s.add_runtime_dependency("faraday_middleware")
12
+ s.add_runtime_dependency("multi_json", ">= 1.0.3", "~> 1.0")
13
+ s.authors = ["Turadg Aleahmad", "Jason Ng PT", "Andy Waite"]
14
+ s.description = "A Ruby wrapper for the Pocket API v3 (Add, Modify and Retrieve)"
15
+ s.email = ["turadg@aleahmad.net", "me@jasonngpt.com"]
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
15
17
  s.files = `git ls-files`.split("\n")
16
- s.homepage = 'https://github.com/turadg/pocket-ruby'
17
- s.name = 'pocket-ruby'
18
+ s.homepage = "https://github.com/turadg/pocket-ruby"
19
+ s.name = "pocket-ruby"
18
20
  s.platform = Gem::Platform::RUBY
19
- s.require_paths = ['lib']
20
- s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
21
+ s.require_paths = ["lib"]
22
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
21
23
  s.rubyforge_project = s.name
22
- s.summary = %q{Ruby wrapper for the Pocket API v3}
24
+ s.summary = "Ruby wrapper for the Pocket API v3"
23
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
26
  s.version = Pocket::VERSION
25
27
  end
@@ -0,0 +1,60 @@
1
+ {
2
+ "item_id": "229279689",
3
+ "resolved_id": "229279689",
4
+ "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview?given",
5
+ "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland",
6
+ "favorite": "0",
7
+ "status": "0",
8
+ "resolved_title": "The Massive Ryder Cup Preview",
9
+ "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview?resolved",
10
+ "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.",
11
+ "is_article": "1",
12
+ "has_video": "1",
13
+ "has_image": "1",
14
+ "word_count": "3197",
15
+ "top_image_url": "https://example.com/image.png",
16
+ "time_added": "1617412992",
17
+ "time_updated": "1617412993",
18
+ "time_read": "1617412994",
19
+ "time_favorited": "1617412995",
20
+ "images": {
21
+ "1": {
22
+ "item_id": "229279689",
23
+ "image_id": "1",
24
+ "src": "http://a.espncdn.com/combiner/i?img=/photo/2012/0927/grant_g_ryder_cr_640.jpg&w=640&h=360",
25
+ "width": "0",
26
+ "height": "0",
27
+ "credit": "Jamie Squire/Getty Images",
28
+ "caption": ""
29
+ }
30
+ },
31
+ "videos": {
32
+ "1": {
33
+ "item_id": "229279689",
34
+ "video_id": "1",
35
+ "src": "http://www.youtube.com/v/Er34PbFkVGk?version=3&hl=en_US&rel=0",
36
+ "width": "420",
37
+ "height": "315",
38
+ "type": "1",
39
+ "vid": "Er34PbFkVGk"
40
+ }
41
+ },
42
+ "tags":{
43
+ "bookmark":{
44
+ "item_id":"229279689",
45
+ "tag":"my-tag-1"
46
+ },
47
+ "gtd":{
48
+ "item_id":"229279689",
49
+ "tag":"my-tag-2"
50
+ }
51
+ },
52
+ "authors":{
53
+ "62344201":{
54
+ "item_id":"229279689",
55
+ "author_id":"62344201",
56
+ "name":"Stephen King",
57
+ "url":"https://example.com/author"
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,165 @@
1
+ require "test_helper"
2
+
3
+ module Pocket
4
+ class VersionTest < Test::Unit::TestCase
5
+ test "from_json" do
6
+ json_string = File.read("test/fixtures/retreive.json")
7
+ article = Pocket::Article.from_json(json_string)
8
+ assert_equal 229279689, article.item_id
9
+ end
10
+
11
+ test "item_id" do
12
+ assert_equal 229279689, article.item_id
13
+ end
14
+
15
+ test "given_url" do
16
+ assert_equal "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview?given", article.given_url
17
+ end
18
+
19
+ test "resolved_url" do
20
+ assert_equal "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview?resolved", article.resolved_url
21
+ end
22
+
23
+ test "given_title" do
24
+ assert_equal "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", article.given_title
25
+ end
26
+
27
+ test "resolved_title" do
28
+ assert_equal "The Massive Ryder Cup Preview", article.resolved_title
29
+ end
30
+
31
+ test "favorite? is false is field is '0'" do
32
+ assert_equal false, article.favorite?
33
+ end
34
+
35
+ test "status" do
36
+ assert_equal 0, article.status
37
+ end
38
+
39
+ test "excerpt" do
40
+ assert_include article.excerpt, "list of things"
41
+ end
42
+
43
+ test "article?" do
44
+ assert article.article?
45
+ end
46
+
47
+ test "has_image?" do
48
+ assert article.has_image?
49
+ end
50
+
51
+ test "image?" do
52
+ refute article.image?
53
+ end
54
+
55
+ test "has_video?" do
56
+ assert article.has_video?
57
+ end
58
+
59
+ test "video?" do
60
+ refute article.video?
61
+ end
62
+
63
+ test "word_count" do
64
+ assert_equal 3197, article.word_count
65
+ end
66
+
67
+ test "resolved_id" do
68
+ assert_equal 229279689, article.resolved_id
69
+ end
70
+
71
+ test "thumbnail" do
72
+ assert_equal "https://example.com/image.png", article.thumbnail
73
+ end
74
+
75
+ test "time_added" do
76
+ assert_equal Time.utc(2021, 4, 3, 1, 23, 12), article.time_added
77
+ end
78
+
79
+ test "time_added is nil if field not present" do
80
+ parsed_response.delete("time_added")
81
+ assert_nil article.time_added
82
+ end
83
+
84
+ test "time_updated" do
85
+ assert_equal Time.utc(2021, 4, 3, 1, 23, 13), article.time_updated
86
+ end
87
+
88
+ test "time_updated is nil if field not present" do
89
+ parsed_response.delete("time_updated")
90
+ assert_nil article.time_updated
91
+ end
92
+
93
+ test "time_read" do
94
+ assert_equal Time.utc(2021, 4, 3, 1, 23, 14), article.time_read
95
+ end
96
+
97
+ test "time_read is nil if field is not present" do
98
+ parsed_response.delete("time_read")
99
+ assert_nil article.time_read
100
+ end
101
+
102
+ test "time_read is nil if field is zero" do
103
+ parsed_response["time_read"] = "0"
104
+ assert_nil article.time_read
105
+ end
106
+
107
+ test "favorited?" do
108
+ assert article.favorited?
109
+ end
110
+
111
+ test "time_favorited" do
112
+ assert_equal Time.utc(2021, 4, 3, 1, 23, 15), article.time_favorited
113
+ end
114
+
115
+ test "time_favorited is nil if field not present" do
116
+ parsed_response.delete("time_favorited")
117
+ assert_nil article.time_favorited
118
+ end
119
+
120
+ test "time_favorited is nil if field is zero" do
121
+ parsed_response["time_favorited"] = "0"
122
+ assert_nil article.time_favorited
123
+ end
124
+
125
+ test "read?" do
126
+ assert article.read?
127
+ end
128
+
129
+ test "read_url" do
130
+ assert_equal "https://getpocket.com/read/229279689", article.read_url
131
+ end
132
+
133
+ test "tags" do
134
+ assert_equal ["my-tag-1", "my-tag-2"], article.tags
135
+ end
136
+
137
+ test "tags returns an empty array if there are no tags" do
138
+ parsed_response.delete("tags")
139
+ assert_equal [], article.tags
140
+ end
141
+
142
+ test "authors" do
143
+ result = article.authors
144
+ assert_equal 1, result.size
145
+ assert_equal "Stephen King", result.first.name
146
+ assert_equal 62344201, result.first.id
147
+ assert_equal "https://example.com/author", result.first.url
148
+ end
149
+
150
+ test "authors returns an empty array if there are no tags" do
151
+ parsed_response.delete("authors")
152
+ assert_equal [], article.authors
153
+ end
154
+
155
+ private
156
+
157
+ def article
158
+ @article ||= Pocket::Article.new(parsed_response)
159
+ end
160
+
161
+ def parsed_response
162
+ @parsed_response ||= JSON.parse(File.read("test/fixtures/retreive.json"))
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,9 @@
1
+ require "test_helper"
2
+
3
+ module Pocket
4
+ class VersionTest < Test::Unit::TestCase
5
+ def test_specifies_a_version
6
+ assert Pocket::VERSION
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+ SimpleCov.start do
5
+ enable_coverage :branch
6
+ end
7
+
8
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
9
+ require "pocket-ruby"
10
+
11
+ require "test-unit"
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pocket-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Turadg Aleahmad
8
8
  - Jason Ng PT
9
+ - Andy Waite
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2021-03-30 00:00:00.000000000 Z
13
+ date: 2021-04-10 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: sinatra
@@ -39,6 +40,62 @@ dependencies:
39
40
  - - ">="
40
41
  - !ruby/object:Gem::Version
41
42
  version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: standard
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: test-unit
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: simplecov
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
42
99
  - !ruby/object:Gem::Dependency
43
100
  name: faraday
44
101
  requirement: !ruby/object:Gem::Requirement
@@ -87,20 +144,6 @@ dependencies:
87
144
  - - ">="
88
145
  - !ruby/object:Gem::Version
89
146
  version: 1.0.3
90
- - !ruby/object:Gem::Dependency
91
- name: hashie
92
- requirement: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 0.4.0
97
- type: :runtime
98
- prerelease: false
99
- version_requirements: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 0.4.0
104
147
  description: A Ruby wrapper for the Pocket API v3 (Add, Modify and Retrieve)
105
148
  email:
106
149
  - turadg@aleahmad.net
@@ -109,10 +152,13 @@ executables: []
109
152
  extensions: []
110
153
  extra_rdoc_files: []
111
154
  files:
155
+ - ".github/workflows/changelog-checker.yml"
156
+ - ".github/workflows/tests.yml"
112
157
  - ".gitignore"
113
158
  - ".yardopts"
114
159
  - CHANGELOG.md
115
160
  - Gemfile
161
+ - Gemfile.lock
116
162
  - LICENSE.md
117
163
  - README.md
118
164
  - Rakefile
@@ -121,6 +167,8 @@ files:
121
167
  - lib/faraday/raise_pocket_error.rb
122
168
  - lib/pocket-ruby.rb
123
169
  - lib/pocket/api.rb
170
+ - lib/pocket/article.rb
171
+ - lib/pocket/author.rb
124
172
  - lib/pocket/client.rb
125
173
  - lib/pocket/client/add.rb
126
174
  - lib/pocket/client/modify.rb
@@ -131,6 +179,10 @@ files:
131
179
  - lib/pocket/oauth.rb
132
180
  - lib/pocket/version.rb
133
181
  - pocket-ruby.gemspec
182
+ - test/fixtures/retreive.json
183
+ - test/pocket/article_test.rb
184
+ - test/pocket/version_test.rb
185
+ - test/test_helper.rb
134
186
  homepage: https://github.com/turadg/pocket-ruby
135
187
  licenses: []
136
188
  metadata: {}
@@ -153,4 +205,8 @@ rubygems_version: 3.0.3
153
205
  signing_key:
154
206
  specification_version: 4
155
207
  summary: Ruby wrapper for the Pocket API v3
156
- test_files: []
208
+ test_files:
209
+ - test/fixtures/retreive.json
210
+ - test/pocket/article_test.rb
211
+ - test/pocket/version_test.rb
212
+ - test/test_helper.rb