Class: Pickpocket::Articles::API
- Inherits:
-
Object
- Object
- Pickpocket::Articles::API
- Defined in:
- lib/pickpocket/articles/api.rb
Constant Summary collapse
- ACTION_DELETE =
'delete'
- STATE_UNREAD =
'unread'
Instance Attribute Summary collapse
-
#token_handler ⇒ Object
readonly
Returns the value of attribute token_handler.
Instance Method Summary collapse
- #delete(article_ids = []) ⇒ Object
-
#initialize ⇒ API
constructor
A new instance of API.
- #retrieve ⇒ Object
Constructor Details
#initialize ⇒ API
Returns a new instance of API.
11 12 13 |
# File 'lib/pickpocket/articles/api.rb', line 11 def initialize @token_handler = Authentication::TokenHandler.new end |
Instance Attribute Details
#token_handler ⇒ Object (readonly)
Returns the value of attribute token_handler.
9 10 11 |
# File 'lib/pickpocket/articles/api.rb', line 9 def token_handler @token_handler end |
Instance Method Details
#delete(article_ids = []) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pickpocket/articles/api.rb', line 28 def delete(article_ids = []) return if article_ids.empty? uri = URI(Pickpocket.config.pocket_send_url) json_action = article_ids.each_with_object([]) do |article_id, array| array << { action: ACTION_DELETE, item_id: article_id } end response = Net::HTTP.post_form(uri, { consumer_key: Pickpocket.config.consumer_key, access_token: access_token, actions: JSON.dump(json_action) }) # TODO: error handling (unauthorized, etc) JSON.parse(response.body) end |
#retrieve ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pickpocket/articles/api.rb', line 15 def retrieve uri = URI(Pickpocket.config.pocket_retrieve_url) response = Net::HTTP.post_form(uri, { consumer_key: Pickpocket.config.consumer_key, access_token: access_token, state: STATE_UNREAD }) # TODO: error handling (unauthorized, etc) JSON.parse(response.body) end |