Class: Boxcab::API
Instance Method Summary collapse
- #create(attributes) ⇒ Object
- #find(id) ⇒ Object
-
#initialize(base_uri, site_handle, api_key) ⇒ API
constructor
A new instance of API.
- #update(id, attributes) ⇒ Object
- #update_site(attributes) ⇒ Object
Constructor Details
#initialize(base_uri, site_handle, api_key) ⇒ API
Returns a new instance of API.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/boxcab/api.rb', line 8 def initialize(base_uri, site_handle, api_key) @site_handle = site_handle @options = { base_uri: base_uri, headers: { 'x-boxcab-site-handle' => site_handle, 'x-boxcab-api-key' => api_key } } end |
Instance Method Details
#create(attributes) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/boxcab/api.rb', line 37 def create(attributes) response = self.class.post('/api/v1/pages.json', @options.merge(body: { page: attributes })) response.success? ? response.parsed_response : nil end |
#find(id) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/boxcab/api.rb', line 19 def find(id) = @options.slice(:base_uri) response = self.class.get("/api/v1/public/#{@site_handle}/pages/#{id}.json", ) response.success? ? response.parsed_response : nil end |
#update(id, attributes) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/boxcab/api.rb', line 45 def update(id, attributes) _attributes = attributes.slice('title', 'url', 'schema', 'position') _attributes['schema'] = _attributes['schema'].to_json response = self.class.put("/api/v1/pages/#{id}.json", @options.merge(body: { page: _attributes })) response.success? end |
#update_site(attributes) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/boxcab/api.rb', line 27 def update_site(attributes) _attributes = attributes.slice(:name, :base_url) response = self.class.put("/api/v1/site.json", @options.merge(body: { site: _attributes })) response.success? end |