pocket-ruby 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98d5e4c5d566026c6e2ee7a7fc51e955de4ee56fe79bf20b93e760466ac91595
4
- data.tar.gz: 3642f95d676252dc502437fb9be6ae5b797d7c5499ce2292cc3c04cedaca5941
3
+ metadata.gz: 820f73644ee1f21cea8033e70e5c3c038b6dc061cb9e05b36c3ede86421763e1
4
+ data.tar.gz: 30744f3d1257e1d7fcee9cda79abf518f4277d996c8716720ec6cc1bbbce59f8
5
5
  SHA512:
6
- metadata.gz: e98bec08220f3f69c841490dd3d9c8a7524a6cb403069df134f951b84ee8fffa4515cef25d2eb67c4f12d61ca6f76a808fd904166fd3ee4e14d0e909d06a7e66
7
- data.tar.gz: f759d86eb1eb79744ecb4c9b9aa422f268db6836f4c1773e83d4b8815680445209e7474463ea3b52116debdec7c44d8ca204efe24d989d9c8e40f7ae42875030
6
+ metadata.gz: acb0b74a3bd7df194b1ed532dc7f54a1eb860d5632f1854aab803c905c9f8c4c7d3fe23b42553507b82165776a892d93ac38f98874cc5c811cbb81dfcd34b76c
7
+ data.tar.gz: e2526ed17125c7c51be1d8baaaa1d30e610858c0968b03348e875aeec75a9384cc566b65b0ca5c02ab85aff5e0288f3fc8d02ce4b364a99e98a820a11debe830
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.0] - 2021-04-03
4
+
5
+ - Add `Pocket::Article` for parsing an article response ([#39](https://github.com/turadg/pocket-ruby/pull/39))
6
+ - Fix Pocket::Client::Retrieve#retrieve params default ([#21](https://github.com/turadg/pocket-ruby/pull/21))
7
+
3
8
  ## [0.0.9] - 2021-04-01
4
9
 
5
10
  - Actually remove unused Hashie dependency ([#35](https://github.com/turadg/pocket-ruby/pull/35))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pocket-ruby (0.0.9)
4
+ pocket-ruby (0.1.0)
5
5
  faraday (>= 0.7)
6
6
  faraday_middleware
7
7
  multi_json (~> 1.0, >= 1.0.3)
@@ -9,6 +9,8 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
+ ast (2.4.2)
13
+ docile (1.3.5)
12
14
  faraday (1.3.0)
13
15
  faraday-net_http (~> 1.0)
14
16
  multipart-post (>= 1.2, < 3)
@@ -19,19 +21,50 @@ GEM
19
21
  multi_json (1.15.0)
20
22
  multi_xml (0.6.0)
21
23
  multipart-post (2.1.1)
24
+ parallel (1.20.1)
25
+ parser (3.0.0.0)
26
+ ast (~> 2.4.1)
22
27
  power_assert (2.0.0)
23
28
  rack (1.6.13)
24
29
  rack-protection (1.5.5)
25
30
  rack
31
+ rainbow (3.0.0)
26
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)
27
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)
28
57
  sinatra (1.3.6)
29
58
  rack (~> 1.4)
30
59
  rack-protection (~> 1.3)
31
60
  tilt (~> 1.3, >= 1.3.3)
61
+ standard (1.0.4)
62
+ rubocop (= 1.11.0)
63
+ rubocop-performance (= 1.10.1)
32
64
  test-unit (3.4.0)
33
65
  power_assert
34
66
  tilt (1.4.1)
67
+ unicode-display_width (2.0.0)
35
68
 
36
69
  PLATFORMS
37
70
  x86_64-darwin-19
@@ -41,7 +74,9 @@ DEPENDENCIES
41
74
  multi_xml
42
75
  pocket-ruby!
43
76
  rake
77
+ simplecov
44
78
  sinatra (~> 1.3.3)
79
+ standard
45
80
  test-unit
46
81
 
47
82
  BUNDLED WITH
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require 'bundler'
1
+ require "bundler"
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
+ require "standard/rake"
5
+
4
6
  require "rake/testtask"
5
7
  Rake::TestTask.new(:test) do |t|
6
8
  t.libs << "test"
@@ -8,24 +10,22 @@ Rake::TestTask.new(:test) do |t|
8
10
  t.test_files = FileList["test/**/*_test.rb"]
9
11
  end
10
12
 
11
- task :default => :test
13
+ task default: [:test, :standard]
12
14
 
13
15
  namespace :doc do
14
- begin
15
- require 'yard'
16
- rescue LoadError
17
- # ignore
18
- else
19
- YARD::Rake::YardocTask.new do |task|
20
- task.files = ['HISTORY.mkd', 'LICENSE.mkd', 'lib/**/*.rb']
21
- task.options = [
22
- '--protected',
23
- '--output-dir', 'doc/yard',
24
- '--tag', 'format:Supported formats',
25
- '--tag', 'authenticated:Requires Authentication',
26
- '--tag', 'rate_limited:Rate Limited',
27
- '--markup', 'markdown',
28
- ]
29
- 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
+ ]
30
30
  end
31
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,8 @@
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__)
5
6
 
6
7
  module Pocket
7
8
  extend Configuration
@@ -9,7 +10,7 @@ module Pocket
9
10
  # Alias for Pocket::Client.new
10
11
  #
11
12
  # @return [Pocket::Client]
12
- def self.client(options={})
13
+ def self.client(options = {})
13
14
  Pocket::Client.new(options)
14
15
  end
15
16
 
@@ -20,7 +21,7 @@ module Pocket
20
21
  end
21
22
 
22
23
  # Delegate to Pocket::Client
23
- def self.respond_to?(method)
24
- return client.respond_to?(method) || super
24
+ def self.respond_to_missing?(method)
25
+ client.respond_to?(method) || super
25
26
  end
26
27
  end
data/lib/pocket/api.rb CHANGED
@@ -1,5 +1,5 @@
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
@@ -8,7 +8,7 @@ module Pocket
8
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,111 @@
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
+ Time.at(Integer(response["time_read"])).utc
92
+ end
93
+
94
+ def favorited?
95
+ Integer(response["time_favorited"]) > 0
96
+ end
97
+
98
+ def time_favorited
99
+ return nil unless response["time_favorited"]
100
+ Time.at(Integer(response["time_favorited"])).utc
101
+ end
102
+
103
+ def read?
104
+ Integer(response["time_read"]) > 0
105
+ end
106
+
107
+ def read_url
108
+ "https://getpocket.com/read/#{item_id}"
109
+ end
110
+ end
111
+ 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
  #
@@ -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,25 +11,25 @@ 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
- 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
- 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
30
+ def get_result(code, options = {})
31
+ params = access_token_params.merge(code: code).merge(options)
32
+ response = connection.post "oauth/authorize", params
33
33
  Hash[URI.decode_www_form(response.body)]
34
34
  end
35
35
 
@@ -37,8 +37,8 @@ module Pocket
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.9'
2
+ VERSION = "0.1.0"
3
3
  end
data/pocket-ruby.gemspec CHANGED
@@ -1,26 +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_development_dependency('rake')
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
8
  s.add_development_dependency("test-unit")
9
- s.add_runtime_dependency('faraday', ['>= 0.7'])
10
- s.add_runtime_dependency('faraday_middleware')
11
- s.add_runtime_dependency('multi_json', '>= 1.0.3', '~> 1.0')
12
- s.authors = ["Turadg Aleahmad","Jason Ng PT", "Andy Waite"]
13
- s.description = %q{A Ruby wrapper for the Pocket API v3 (Add, Modify and Retrieve)}
14
- s.email = ['turadg@aleahmad.net',"me@jasonngpt.com"]
15
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
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) }
16
17
  s.files = `git ls-files`.split("\n")
17
- s.homepage = 'https://github.com/turadg/pocket-ruby'
18
- s.name = 'pocket-ruby'
18
+ s.homepage = "https://github.com/turadg/pocket-ruby"
19
+ s.name = "pocket-ruby"
19
20
  s.platform = Gem::Platform::RUBY
20
- s.require_paths = ['lib']
21
- 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=
22
23
  s.rubyforge_project = s.name
23
- s.summary = %q{Ruby wrapper for the Pocket API v3}
24
+ s.summary = "Ruby wrapper for the Pocket API v3"
24
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
26
  s.version = Pocket::VERSION
26
27
  end
@@ -0,0 +1,42 @@
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
+ }
@@ -0,0 +1,133 @@
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 "favorited?" do
103
+ assert article.favorited?
104
+ end
105
+
106
+ test "time_favorited" do
107
+ assert_equal Time.utc(2021, 4, 3, 1, 23, 15), article.time_favorited
108
+ end
109
+
110
+ test "time_favorited is nil if field not present" do
111
+ parsed_response.delete("time_favorited")
112
+ assert_nil article.time_favorited
113
+ end
114
+
115
+ test "read?" do
116
+ assert article.read?
117
+ end
118
+
119
+ test "read_url" do
120
+ assert_equal "https://getpocket.com/read/229279689", article.read_url
121
+ end
122
+
123
+ private
124
+
125
+ def article
126
+ @article ||= Pocket::Article.new(parsed_response)
127
+ end
128
+
129
+ def parsed_response
130
+ @parsed_response ||= JSON.parse(File.read("test/fixtures/retreive.json"))
131
+ end
132
+ end
133
+ end
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
3
  module Pocket
4
4
  class VersionTest < Test::Unit::TestCase
data/test/test_helper.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "simplecov"
4
+ SimpleCov.start do
5
+ enable_coverage :branch
6
+ end
7
+
3
8
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
9
  require "pocket-ruby"
5
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pocket-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Turadg Aleahmad
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-04-02 00:00:00.000000000 Z
13
+ date: 2021-04-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
@@ -54,6 +54,20 @@ dependencies:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
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'
57
71
  - !ruby/object:Gem::Dependency
58
72
  name: test-unit
59
73
  requirement: !ruby/object:Gem::Requirement
@@ -68,6 +82,20 @@ dependencies:
68
82
  - - ">="
69
83
  - !ruby/object:Gem::Version
70
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'
71
99
  - !ruby/object:Gem::Dependency
72
100
  name: faraday
73
101
  requirement: !ruby/object:Gem::Requirement
@@ -139,6 +167,7 @@ files:
139
167
  - lib/faraday/raise_pocket_error.rb
140
168
  - lib/pocket-ruby.rb
141
169
  - lib/pocket/api.rb
170
+ - lib/pocket/article.rb
142
171
  - lib/pocket/client.rb
143
172
  - lib/pocket/client/add.rb
144
173
  - lib/pocket/client/modify.rb
@@ -149,6 +178,8 @@ files:
149
178
  - lib/pocket/oauth.rb
150
179
  - lib/pocket/version.rb
151
180
  - pocket-ruby.gemspec
181
+ - test/fixtures/retreive.json
182
+ - test/pocket/article_test.rb
152
183
  - test/pocket/version_test.rb
153
184
  - test/test_helper.rb
154
185
  homepage: https://github.com/turadg/pocket-ruby
@@ -174,5 +205,7 @@ signing_key:
174
205
  specification_version: 4
175
206
  summary: Ruby wrapper for the Pocket API v3
176
207
  test_files:
208
+ - test/fixtures/retreive.json
209
+ - test/pocket/article_test.rb
177
210
  - test/pocket/version_test.rb
178
211
  - test/test_helper.rb