Class: Latergram::Publications
- Inherits:
-
Object
- Object
- Latergram::Publications
- Defined in:
- lib/latergram/publications.rb
Constant Summary collapse
- ENDPOINT =
'publications'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
Instance Method Summary collapse
- #all(page: 1, per_page: 10) ⇒ Object
- #create(text:, images:) ⇒ Object
- #destroy(publication_id) ⇒ Object
- #find(publication_id) ⇒ Object
-
#initialize(api_key, api_url:) ⇒ Publications
constructor
A new instance of Publications.
- #update(publication_id, text: nil) ⇒ Object
Constructor Details
#initialize(api_key, api_url:) ⇒ Publications
Returns a new instance of Publications.
12 13 14 15 |
# File 'lib/latergram/publications.rb', line 12 def initialize(api_key, api_url:) @api_key = api_key @api_url = api_url end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/latergram/publications.rb', line 8 def api_key @api_key end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
8 9 10 |
# File 'lib/latergram/publications.rb', line 8 def api_url @api_url end |
Instance Method Details
#all(page: 1, per_page: 10) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/latergram/publications.rb', line 17 def all(page: 1, per_page: 10) response = requester.get(ENDPOINT, page: page, per_page: per_page) raise Latergram::Error, response.body unless response.status == 200 JSON.parse(response.body) end |
#create(text:, images:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/latergram/publications.rb', line 33 def create(text:, images:) check_images(images) parameters = { publication: { text: text, images: images }.compact } response = requester.post(ENDPOINT, parameters) raise Latergram::Error, response.body unless response.status == 200 JSON.parse(response.body) end |
#destroy(publication_id) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/latergram/publications.rb', line 53 def destroy(publication_id) response = requester.delete(ENDPOINT + "/#{publication_id}") raise Latergram::Error, response.body unless response.status == 200 JSON.parse(response.body) end |
#find(publication_id) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/latergram/publications.rb', line 25 def find(publication_id) response = requester.get(ENDPOINT + "/#{publication_id}") raise Latergram::Error, response.body unless response.status == 200 JSON.parse(response.body) end |
#update(publication_id, text: nil) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/latergram/publications.rb', line 44 def update(publication_id, text: nil) parameters = { publication: { text: text }.compact } response = requester.put(ENDPOINT + "/#{publication_id}", parameters) raise Latergram::Error, response.body unless response.status == 200 JSON.parse(response.body) end |