Class: BookableCloud::ApiClient

Inherits:
Object
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/bookable_cloud/api_client.rb

Instance Method Summary collapse

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_urlObject



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_themeObject



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_assetsObject



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_urlObject



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