restpack-core-client 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/lib/restpack-core-client/api.rb +26 -1
- data/lib/restpack-core-client/cache.rb +9 -7
- data/lib/restpack-core-client/models/application.rb +16 -0
- data/lib/restpack-core-client/models/channel.rb +26 -0
- data/lib/restpack-core-client/models/configuration.rb +19 -0
- data/lib/restpack-core-client/models/domain.rb +18 -0
- data/lib/restpack-core-client/version.rb +1 -1
- data/spec/cache_spec.rb +1 -17
- metadata +5 -1
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2013 Gavin Joyce and
|
1
|
+
Copyright (c) 2013 Gavin Joyce and RestPack contributors
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
4
|
this software and associated documentation files (the "Software"), to deal in
|
@@ -1,3 +1,8 @@
|
|
1
|
+
require_relative 'models/channel'
|
2
|
+
require_relative 'models/application'
|
3
|
+
require_relative 'models/domain'
|
4
|
+
require_relative 'models/configuration'
|
5
|
+
|
1
6
|
module RestPack
|
2
7
|
module Core
|
3
8
|
module Client
|
@@ -10,7 +15,9 @@ module RestPack
|
|
10
15
|
def get_channel(id)
|
11
16
|
p "API.get_channel(#{id})"
|
12
17
|
json = RestClient.get("http://:#{@password}@#{@domain}/api/v1/channels/#{id}.json")
|
13
|
-
JSON.parse(json, :symbolize_keys => true)
|
18
|
+
data = JSON.parse(json, :symbolize_keys => true)
|
19
|
+
|
20
|
+
hydrate_channel(data)
|
14
21
|
end
|
15
22
|
|
16
23
|
def get_domain(identifier)
|
@@ -19,6 +26,24 @@ module RestPack
|
|
19
26
|
result = JSON.parse(json, :symbolize_keys => true)
|
20
27
|
result[:domains].first
|
21
28
|
end
|
29
|
+
|
30
|
+
def hydrate_channel(channel_response)
|
31
|
+
channel = Channel.new(channel_response)
|
32
|
+
|
33
|
+
channel_response[:applications].each do |application_data|
|
34
|
+
Application.new(application_data, channel)
|
35
|
+
end
|
36
|
+
|
37
|
+
channel_response[:domains].each do |domain_data|
|
38
|
+
Domain.new(domain_data, channel)
|
39
|
+
end
|
40
|
+
|
41
|
+
channel_response[:configurations].each do |configuration_data|
|
42
|
+
Configuration.new(configuration_data, channel)
|
43
|
+
end
|
44
|
+
|
45
|
+
channel
|
46
|
+
end
|
22
47
|
end
|
23
48
|
end
|
24
49
|
end
|
@@ -4,7 +4,7 @@ module RestPack
|
|
4
4
|
class Cache
|
5
5
|
def initialize(api)
|
6
6
|
@api = api
|
7
|
-
@
|
7
|
+
@channel_ids = {}
|
8
8
|
@channels = {}
|
9
9
|
end
|
10
10
|
|
@@ -13,16 +13,18 @@ module RestPack
|
|
13
13
|
Cache.new(api)
|
14
14
|
end
|
15
15
|
|
16
|
-
def get_channel(domain_identifier)
|
17
|
-
|
18
|
-
|
16
|
+
def get_channel(domain_identifier)
|
17
|
+
channel_id = get_channel_id(domain_identifier)
|
18
|
+
|
19
|
+
@channels[channel_id] ||= @api.get_channel(channel_id)
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
@
|
22
|
+
def get_channel_id(domain_identifier)
|
23
|
+
@channel_ids[domain_identifier] ||= @api.get_domain(domain_identifier)[:channel_id]
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RestPack::Core::Client
|
2
|
+
class Application
|
3
|
+
attr_accessor :id, :name, :channel, :domains, :configurations
|
4
|
+
|
5
|
+
def initialize(data, channel)
|
6
|
+
@domains = []
|
7
|
+
@configurations = []
|
8
|
+
|
9
|
+
@id = data[:id]
|
10
|
+
@name = data[:name]
|
11
|
+
|
12
|
+
@channel = channel
|
13
|
+
@channel.applications << self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RestPack::Core::Client
|
2
|
+
class Channel
|
3
|
+
attr_accessor :id, :name, :applications, :domains, :configurations
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@applications = []
|
7
|
+
@domains = []
|
8
|
+
@configurations = []
|
9
|
+
|
10
|
+
@id = data[:channel][:id]
|
11
|
+
@name = data[:channel][:name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_application(id)
|
15
|
+
@applications.find { |a| a.id == id }
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_domain(id)
|
19
|
+
@domains.find { |a| a.id == id }
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_configuration(id)
|
23
|
+
@configurations.find { |a| a.id == id }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RestPack::Core::Client
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :id, :key, :value, :channel, :application, :domain
|
4
|
+
|
5
|
+
def initialize(data, channel)
|
6
|
+
@id = data[:id]
|
7
|
+
@key = data[:key]
|
8
|
+
@value = data[:value]
|
9
|
+
|
10
|
+
@channel = channel
|
11
|
+
@application = channel.get_application(data[:application_id])
|
12
|
+
@domain = channel.get_domain(data[:domain_id])
|
13
|
+
|
14
|
+
@channel.configurations << self
|
15
|
+
@application.configurations << self if @application
|
16
|
+
@domain.configurations << self if @domain
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RestPack::Core::Client
|
2
|
+
class Domain
|
3
|
+
attr_accessor :id, :identifier, :channel, :application, :configurations
|
4
|
+
|
5
|
+
def initialize(data, channel)
|
6
|
+
@configurations = []
|
7
|
+
|
8
|
+
@id = data[:id]
|
9
|
+
@identifier = data[:identifier]
|
10
|
+
|
11
|
+
@channel = channel
|
12
|
+
@application = channel.get_application(data[:application_id])
|
13
|
+
|
14
|
+
@channel.domains << self
|
15
|
+
@application.domains << self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/cache_spec.rb
CHANGED
@@ -6,22 +6,6 @@ describe RestPack::Core::Client::Cache do
|
|
6
6
|
let(:cache) { RestPack::Core::Client::Cache.new(api) }
|
7
7
|
|
8
8
|
context "with an empty cache" do
|
9
|
-
|
10
|
-
describe "#get_domain" do
|
11
|
-
it "makes a single API call" do
|
12
|
-
api.should_receive(:get_domain).with('www.incremental.ie').and_return({ id: 1, channel_id: 2 })
|
13
|
-
3.times { cache.get_domain('www.incremental.ie') }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#get_channel" do
|
18
|
-
it "makes single API calls" do
|
19
|
-
api.should_receive(:get_domain).with('www.incremental.ie').and_return({ id: 1, channel_id: 2 })
|
20
|
-
api.should_receive(:get_channel).with(2).and_return({ channel_id: 2 })
|
21
|
-
|
22
|
-
3.times { cache.get_channel('www.incremental.ie') }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
9
|
+
pending
|
26
10
|
end
|
27
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restpack-core-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -91,6 +91,10 @@ files:
|
|
91
91
|
- lib/restpack-core-client.rb
|
92
92
|
- lib/restpack-core-client/api.rb
|
93
93
|
- lib/restpack-core-client/cache.rb
|
94
|
+
- lib/restpack-core-client/models/application.rb
|
95
|
+
- lib/restpack-core-client/models/channel.rb
|
96
|
+
- lib/restpack-core-client/models/configuration.rb
|
97
|
+
- lib/restpack-core-client/models/domain.rb
|
94
98
|
- lib/restpack-core-client/version.rb
|
95
99
|
- restpack-core-client.gemspec
|
96
100
|
- spec/cache_spec.rb
|