Class: RestPack::Core::Client::API

Inherits:
Object
  • Object
show all
Defined in:
lib/restpack_core_client/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain, access_key) ⇒ API

Returns a new instance of API.



10
11
12
13
# File 'lib/restpack_core_client/api.rb', line 10

def initialize(domain, access_key)
  @domain = domain
  @access_key = access_key
end

Instance Method Details

#get_channel(id) ⇒ Object



15
16
17
18
19
20
# File 'lib/restpack_core_client/api.rb', line 15

def get_channel(id)
  json = RestClient.get("http://:#{@access_key}@#{@domain}/api/v1/channels/#{id}.json")
  data = Yajl::Parser.parse(json, :symbolize_keys => true)

  hydrate_channel(data)
end

#get_domain(host) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/restpack_core_client/api.rb', line 22

def get_domain(host)
  json = RestClient.get("http://:#{@access_key}@#{@domain}/api/v1/domains/search.json?host=#{host}")
  result = Yajl::Parser.parse(json, :symbolize_keys => true)

  raise "host is not configured: #{host}" if result.empty?

  result[:domains].first
end

#root_configurationsObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/restpack_core_client/api.rb', line 31

def root_configurations
  json = RestClient.get("http://:#{@access_key}@#{@domain}/api/v1/configurations/root.json")
  data = Yajl::Parser.parse(json, :symbolize_keys => true)

  configurations = []
  data[:configurations].each do |configuration_data|
    configurations << Configuration.new(configuration_data)
  end
  configurations
end