Class: Socialfred::Publications
- Inherits:
-
Object
- Object
- Socialfred::Publications
- Defined in:
- lib/socialfred/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(publish_at: nil, text:, images: nil, options: nil) ⇒ Object
- #destroy(publication_id) ⇒ Object
- #find(publication_id) ⇒ Object
-
#initialize(api_key, api_url:) ⇒ Publications
constructor
A new instance of Publications.
- #update(publication_id, publish_at: nil, text: nil, images: nil, options: nil) ⇒ Object
Constructor Details
#initialize(api_key, api_url:) ⇒ Publications
Returns a new instance of Publications.
12 13 14 15 |
# File 'lib/socialfred/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/socialfred/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/socialfred/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/socialfred/publications.rb', line 17 def all(page: 1, per_page: 10) response = requester.get(ENDPOINT, page: page, per_page: per_page) raise Socialfred::Error, response.body unless response.status == 200 JSON.parse(response.body) end |
#create(publish_at: nil, text:, images: nil, options: nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/socialfred/publications.rb', line 33 def create(publish_at: nil, text:, images: nil, options: nil) check_images(images) if images publish_at = Time.parse(publish_at.to_s).iso8601 if publish_at parameters = { publication: { published_at: publish_at, text: text, images: images, options: }.compact } response = requester.post(ENDPOINT, parameters) raise Socialfred::Error, response.body unless response.status == 200 JSON.parse(response.body) end |
#destroy(publication_id) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/socialfred/publications.rb', line 57 def destroy(publication_id) response = requester.delete(ENDPOINT + "/#{publication_id}") raise Socialfred::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/socialfred/publications.rb', line 25 def find(publication_id) response = requester.get(ENDPOINT + "/#{publication_id}") raise Socialfred::Error, response.body unless response.status == 200 JSON.parse(response.body) end |
#update(publication_id, publish_at: nil, text: nil, images: nil, options: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/socialfred/publications.rb', line 45 def update(publication_id, publish_at: nil, text: nil, images: nil, options: nil) check_images(images) if images publish_at = Time.parse(publish_at.to_s).iso8601 if publish_at parameters = { publication: { published_at: publish_at, text: text, images: images, options: }.compact } response = requester.put(ENDPOINT + "/#{publication_id}", parameters) raise Socialfred::Error, response.body unless response.status == 200 JSON.parse(response.body) end |