Class: Spearly::Cloud::Client
- Inherits:
-
Object
- Object
- Spearly::Cloud::Client
- Defined in:
- lib/spearly/cloud/client.rb
Instance Method Summary collapse
- #get_site(site_id) ⇒ Object
- #get_sites(params) ⇒ Object
-
#initialize(token) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(token) ⇒ Client
Returns a new instance of Client.
6 7 8 |
# File 'lib/spearly/cloud/client.rb', line 6 def initialize(token) @token = token end |
Instance Method Details
#get_site(site_id) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/spearly/cloud/client.rb', line 27 def get_site(site_id) uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/sites/#{site_id}" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.get(uri_parsed, nil, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 200 JSON.parse(res.body)['data'] else {} end end |
#get_sites(params) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/spearly/cloud/client.rb', line 10 def get_sites(params) uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/sites" uri_parsed = Addressable::URI.parse(uri).normalize.to_s client = Faraday.default_connection res = client.get(uri_parsed, params, 'Accept' => 'application/vnd.spearly.v2+json', 'Authorization' => @token) if res.status == 200 JSON.parse(res.body)['data'] else [] end end |