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
21
# File 'lib/restpack-core-client/api.rb', line 15

def get_channel(id)   
  p "API.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



23
24
25
26
27
28
29
30
31
# File 'lib/restpack-core-client/api.rb', line 23

def get_domain(host)
  p "API.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

#hydrate_channel(channel_response) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/restpack-core-client/api.rb', line 45

def hydrate_channel(channel_response)
  channel = Channel.new(channel_response)
  
  channel_response[:applications].each do |application_data|
    Application.new(application_data, channel)
  end
  
  channel_response[:domains].each do |domain_data|
    Domain.new(domain_data, channel)
  end
  
  channel_response[:configurations].each do |configuration_data|
    Configuration.new(configuration_data, channel)
  end
  
  channel
end

#root_configurationsObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/restpack-core-client/api.rb', line 33

def root_configurations   
  p "API.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