getpocket 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDBjZWJhYjViMGZiMGU0OGVjYWFhNmM3ZjcxNmQyMzJkMTYyMzBhNA==
4
+ OWU3ZWE3Yzk0Yjk0ZTI5MDQyMGEzYjI5MWVjYzU4NWFhYzhhMjdiMA==
5
5
  data.tar.gz: !binary |-
6
- NmJlYzUwZWQxNTMwNjYwZjg3ZTdkOWM3OGRlMDdkMzQ2YzJkZmYwNA==
6
+ MjhjYWNlMzYxMjZhMGE0ODE2MWE4OWI4ZTc1ZTkzZGY0YzI0NmU4MQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MWNlNzI2ZWRhODc1MDYxNjM5Y2ViODIwNGI0M2NiOTk4N2ViNWMxODNlZWJl
10
- MDQyY2FjZmU1NDEzYzIxYjAxNTMyNWIwM2Q0ZjFjNjI5OWRkZTZiNjZlZWYx
11
- MTYwZjY2NzVmOTY4ZDQ5OGI0MWJhNWQwZDQxNTIxNjU1ZjQyMjc=
9
+ Mzc2NmI4MjBkMDYyODdhN2FiN2ExZjRmODY5Mzk5ZTg5MDhlNmI5MDJiMDM4
10
+ M2JlMzlmNGMxY2I5MzI5NDU4NjQwZTE5Y2RkOTIxMTBjOWNhY2ZmMWE1ZTMy
11
+ OTcxNDcyY2UwNmE4NmQ2N2ZkNmE2MWI1YWQ1MmZhYjUyZjIyODk=
12
12
  data.tar.gz: !binary |-
13
- MGY0YjMwYThlYTgwZGE5ZjFkNjZiY2ViZjdmYzk0N2RmZTA3YzlkNzliZTRh
14
- ODk0MTMwODc3MDA4YWM4ZmQyYTQyY2FkYzNhYmQ0MjgzYzY0ZjNmN2I5YzY5
15
- NGMyMTJiMThiNjE2NTA4MzExNjU4NTYxZjI1OGQ2NTkzY2JlYmU=
13
+ MGMyZTIyZGQ3ZjY3MGY3MGM1NjJlY2U2NTFhNjcxOTMxZmViMWQzOTlkMjY5
14
+ MjljOTE4YTI2NWI4NTVhYzgyNGJmNDI2NzE4YjNhNTI4MjIxOTNkYjkxNDBl
15
+ NWM0MzkyNDJmNWI3OWFiZWI4MTJhNTk5ZDZjOTFjMzY4YWQ4ZmU=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pocket_api.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ getpocket (0.0.2)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ httparty (0.11.0)
11
+ multi_json (~> 1.0)
12
+ multi_xml (>= 0.5.2)
13
+ minitest (4.7.4)
14
+ multi_json (1.7.3)
15
+ multi_xml (0.5.3)
16
+ rake (10.0.4)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler (~> 1.3)
23
+ getpocket!
24
+ minitest
25
+ rake
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alex Chee
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pocket_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "getpocket"
8
+ spec.version = PocketApi::VERSION
9
+ spec.authors = ["Alex Chee"]
10
+ spec.email = ["alexchee11@gmail.com"]
11
+ spec.description = %q{API Wrapper for Pocket (was Read It Later)}
12
+ spec.summary = %q{API Wrapper for Pocket (was Read It Later)}
13
+ spec.homepage = "https://github.com/alexchee/pocket_api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_dependency "httparty"
25
+ end
@@ -0,0 +1,85 @@
1
+ require 'httparty'
2
+ require "pocket_api/version"
3
+ require "pocket_api/connection"
4
+
5
+ module PocketApi
6
+ class <<self
7
+ attr_accessor :client_key
8
+ attr_accessor :access_token
9
+
10
+ def configure(credentials={})
11
+ @client_key = credentials[:client_key]
12
+ @access_token = credentials[:access_token]
13
+ end
14
+
15
+ # Retrieve API
16
+ # Options:
17
+ # * state
18
+ # unread = only return unread items (default)
19
+ # archive = only return archived items
20
+ # all = return both unread and archived items
21
+ # * favorite
22
+ # 0 = only return un-favorited items
23
+ # 1 = only return favorited items
24
+ # * tag
25
+ # tag_name = only return items tagged with tag_name
26
+ # _untagged_ = only return untagged items
27
+ # * contentType
28
+ # article = only return articles
29
+ # video = only return videos or articles with embedded videos
30
+ # image = only return images
31
+ # * sort
32
+ # newest = return items in order of newest to oldest
33
+ # oldest = return items in order of oldest to newest
34
+ # title = return items in order of title alphabetically
35
+ # site = return items in order of url alphabetically
36
+ # * detailType
37
+ # simple = only return the titles and urls of each item
38
+ # complete = return all data about each item, including tags, images, authors, videos and more
39
+ # * search - search query
40
+ # * domain - search within a domain
41
+ # * since - timestamp of modifed items after a date
42
+ # * count - limit of items to return
43
+ # * offset - Used only with count; start returning from offset position of results
44
+ def retrieve(options={})
45
+ response = request(:get, "/v3/get", {:body => options})
46
+ response["list"]
47
+ end
48
+
49
+ # Add API
50
+ # Options:
51
+ # * title
52
+ # * tags - comma-seperated list of tags
53
+ # * tweet_id - Twitter tweet_id
54
+ def add(url, options={})
55
+ request(:post, '/v3/add', :body => {:url => url}.merge(options))
56
+ end
57
+
58
+ # Modify API
59
+ # Actions:
60
+ # * add
61
+ # * archive
62
+ # * readd - re-add
63
+ # * favorite
64
+ # * unfavorite
65
+ # * delete
66
+ # * tags_add
67
+ # * tags_remove
68
+ # * tags_replace
69
+ # * tags_clear
70
+ # * tags_rename
71
+ def modify(action, options={})
72
+ request(:post, '/v3/send', :body => {:action => action}.merge(options))
73
+ end
74
+
75
+
76
+ def request(method, *arguments)
77
+ arguments[1] ||= {}
78
+ arguments[1][:body] ||= {}
79
+ arguments[1][:body] = MultiJson.dump(arguments[1][:body].merge({:consumer_key => @client_key, :access_token => @access_token}))
80
+ puts arguments.inspect
81
+ Connection.__send__(method.downcase.to_sym, *arguments)
82
+ end
83
+
84
+ end # <<self
85
+ end
@@ -0,0 +1,45 @@
1
+ module PocketApi
2
+ class Connection
3
+ include HTTParty
4
+ base_uri 'https://getpocket.com'
5
+ headers "Content-Type" => "application/json; charset=UTF-8"
6
+ headers "X-Accept" => "application/json"
7
+
8
+ class <<self
9
+ attr_accessor :client_key
10
+ attr_accessor :request_token
11
+
12
+ #####################################################
13
+ # OAuth authorization Helpers
14
+ # Sample Workflow:
15
+ # 1. generate_authorize_url, redirect user to URL
16
+ # 2. generate_access_token if user comes back
17
+ # 3. Do a sample call to API to see if it works
18
+ #####################################################
19
+ def generate_request_token(body_options={}, headers_options={})
20
+ response = post("/v3/oauth/request", {:body => MultiJson.dump({:consumer_key => @client_key}.merge(body_options)), :headers => {"Content-Type" => "application/json; charset=UTF-8", "X-Accept" => "application/json"}.merge(headers_options)})
21
+ if response.success? && response.parsed_response["code"]
22
+ # Should be a string body like "code=12345678"
23
+ @request_token = response.parsed_response["code"]
24
+ else
25
+ raise "could not generate request token: #{response.inspect}"
26
+ end
27
+ end
28
+
29
+ def generate_access_token(request_token)
30
+ response = post("/auth/authorize", {:body => MultiJson.dump({:code => @request_token, :consumer_key => @client_key}), :headers => {"Content-Type" => "application/json; charset=UTF-8", "X-Accept" => "application/json"}})
31
+ response.parsed_response["access_token"]
32
+ end
33
+
34
+ def generate_authorize_url(redirect_uri, failed_uri=nil, state=nil)
35
+ failed_uri ||= redirect_uri
36
+ @request_token = generate_request_token({:redirect_uri => failed_uri})
37
+
38
+ "#{default_options[:base_uri]}/v3/oauth/request?request_token=#{CGI.escape(request_token)}&redirect_uri=#{CGI.escape(redirect_uri)}#{"&state=#{CGI.escape(state)}"if state}"
39
+ end
40
+
41
+ end # <<self
42
+
43
+
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module PocketApi
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+ require 'pocket_api'
7
+
8
+ describe PocketApi do
9
+ describe "configure" do
10
+ it "sets client_key and access_token" do
11
+ PocketApi.configure(:client_key => "mykey", :access_token => "myat")
12
+ PocketApi.client_key.must_equal "mykey"
13
+ PocketApi.access_token.must_equal "myat"
14
+ end
15
+ end
16
+
17
+ describe "request" do
18
+ it "should convert :body of argument into JSON"
19
+ it "should insert consumer_key and access_token into argument :body"
20
+ it "should call Connection.get"
21
+ it "should call Connection.post"
22
+ end
23
+
24
+ describe "retrieve" do
25
+ end
26
+
27
+ describe "add" do
28
+ end
29
+
30
+ describe "modify" do
31
+ end
32
+
33
+ end
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+ require 'pocket_api'
7
+
8
+ describe PocketApi::Connection do
9
+ it "sets default base_uri to https://getpocket.com" do
10
+ PocketApi::Connection.base_uri.must_equal "https://getpocket.com"
11
+ end
12
+
13
+ it "sets default Content-Type and X-Accept headers for application/json" do
14
+ default_headers = PocketApi::Connection.default_options[:headers]
15
+ default_headers["Content-Type"].wont_be_nil
16
+ default_headers["Content-Type"].must_match /^application\/json/
17
+ default_headers["X-Accept"].wont_be_nil
18
+ default_headers["X-Accept"].must_match /^application\/json/
19
+ end
20
+
21
+ describe "generate_request_token" do
22
+ it "returns params :code if response success"
23
+ it "raises error if response not success or params :code is missing"
24
+ end
25
+
26
+ describe "generate_access_token" do
27
+ it "returns params :code if response success"
28
+ it "raises error if response not success or params :code is missing"
29
+ end
30
+
31
+ describe "generate_authorize_url" do
32
+ it "return https://getpocket.com/v3/oauth/request with params request token and redirect_uri"
33
+ it "return https://getpocket.com/v3/oauth/request with params request token, redirect_uri, and state"
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getpocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chee
@@ -74,7 +74,17 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
77
80
  - README.md
81
+ - Rakefile
82
+ - getpocket.gemspec
83
+ - lib/pocket_api.rb
84
+ - lib/pocket_api/connection.rb
85
+ - lib/pocket_api/version.rb
86
+ - tests/test_pocket_api.rb
87
+ - tests/test_pocket_api_connection.rb
78
88
  homepage: https://github.com/alexchee/pocket_api
79
89
  licenses:
80
90
  - MIT