Class: Dato::Site::Client
- Inherits:
-
Object
- Object
- Dato::Site::Client
- Defined in:
- lib/dato/site/client.rb
Constant Summary collapse
- REPOS =
{ fields: Repo::Field, item_types: Repo::ItemType, menu_items: Repo::MenuItem, site: Repo::Site, upload_requests: Repo::UploadRequest, users: Repo::User, items: Repo::Item }.freeze
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#extra_headers ⇒ Object
readonly
Returns the value of attribute extra_headers.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(token, options = {}) ⇒ Client
constructor
A new instance of Client.
- #request(*args) ⇒ Object
- #upload_file(path_or_url) ⇒ Object
- #upload_image(path_or_url) ⇒ Object
Constructor Details
#initialize(token, options = {}) ⇒ Client
Returns a new instance of Client.
38 39 40 41 42 |
# File 'lib/dato/site/client.rb', line 38 def initialize(token, = {}) @token = token @base_url = [:base_url] || 'https://site-api.datocms.com' @extra_headers = [:extra_headers] || {} end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
36 37 38 |
# File 'lib/dato/site/client.rb', line 36 def base_url @base_url end |
#extra_headers ⇒ Object (readonly)
Returns the value of attribute extra_headers.
36 37 38 |
# File 'lib/dato/site/client.rb', line 36 def extra_headers @extra_headers end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
36 37 38 |
# File 'lib/dato/site/client.rb', line 36 def schema @schema end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
36 37 38 |
# File 'lib/dato/site/client.rb', line 36 def token @token end |
Instance Method Details
#request(*args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dato/site/client.rb', line 64 def request(*args) connection.send(*args).body.with_indifferent_access rescue Faraday::SSLError => e raise e if ENV['SSL_CERT_FILE'] == Cacert.pem Cacert.set_in_env request(*args) rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e raise e rescue Faraday::ClientError => e raise ApiError, e end |