Class: BookableCloud::ApiClient
- Inherits:
-
Object
- Object
- BookableCloud::ApiClient
- Includes:
- Thor::Actions
- Defined in:
- lib/bookable_cloud/api_client.rb
Instance Method Summary collapse
- #base_url ⇒ Object
- #get_asset(asset) ⇒ Object
- #get_theme ⇒ Object
-
#initialize(config) ⇒ ApiClient
constructor
class Response attr_reader :json, :success.
- #list_assets ⇒ Object
- #tenant_url ⇒ Object
- #update_asset(key, body) ⇒ Object
Constructor Details
#initialize(config) ⇒ ApiClient
class Response
attr_reader :json, :success
def initialize(success: true, json: nil)
@success = success
@json = json
end
end
17 18 19 |
# File 'lib/bookable_cloud/api_client.rb', line 17 def initialize(config) @config = config end |
Instance Method Details
#base_url ⇒ Object
25 26 27 |
# File 'lib/bookable_cloud/api_client.rb', line 25 def base_url tenant_url.to_s + "/admin" end |
#get_asset(asset) ⇒ Object
50 51 52 53 54 |
# File 'lib/bookable_cloud/api_client.rb', line 50 def get_asset(asset) json = get_json "/themes/#{@config["theme_id"]}/assets.json", params: { key: asset } json["asset"] end |
#get_theme ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bookable_cloud/api_client.rb', line 29 def get_theme uri = URI.parse(base_url + "/themes/#{@config["theme_id"]}.json") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request["Authorization"] = "Bearer #{@config["access_token"]}" http.request(request) end |
#list_assets ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/bookable_cloud/api_client.rb', line 42 def list_assets json = get_json "/themes/#{@config["theme_id"]}/assets.json" if assets = json["assets"] assets.collect { |asset| asset["key"] } end end |
#tenant_url ⇒ Object
21 22 23 |
# File 'lib/bookable_cloud/api_client.rb', line 21 def tenant_url @config["tenant_url"] end |
#update_asset(key, body) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/bookable_cloud/api_client.rb', line 56 def update_asset(key, body) json = put_json "/themes/#{@config["theme_id"]}/assets.json", params: { "asset[key]" => key, "asset[value]" => body } end |