restpack-core-client 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Gemfile +8 -0
- data/LICENSE +19 -0
- data/README.md +20 -0
- data/Rakefile +31 -0
- data/lib/restpack-core-client/api.rb +25 -0
- data/lib/restpack-core-client/cache.rb +28 -0
- data/lib/restpack-core-client/version.rb +7 -0
- data/lib/restpack-core-client.rb +5 -0
- data/restpack-core-client.gemspec +25 -0
- data/spec/cache_spec.rb +27 -0
- data/spec/spec_helper.rb +6 -0
- metadata +124 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 Gavin Joyce and RESTpack contributors
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# RESTpack core.client [![Build Status](https://travis-ci.org/RESTpack/restpack-core-client.png?branch=master)](https://travis-ci.org/RESTpack/restpack-core-client) [![Dependency Status](https://gemnasium.com/RESTpack/restpack-core-client.png)](https://gemnasium.com/RESTpack/restpack-core-client)
|
2
|
+
|
3
|
+
A client gem for restpack-core-service
|
4
|
+
|
5
|
+
## Using the gem
|
6
|
+
|
7
|
+
Instructions coming soon...
|
8
|
+
|
9
|
+
## Developer Environment Setup
|
10
|
+
|
11
|
+
```
|
12
|
+
bundle install
|
13
|
+
```
|
14
|
+
|
15
|
+
## Running Tests
|
16
|
+
|
17
|
+
```
|
18
|
+
rake test
|
19
|
+
```
|
20
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
task :default => :test
|
4
|
+
task :test => :spec
|
5
|
+
|
6
|
+
begin
|
7
|
+
require "rspec/core/rake_task"
|
8
|
+
|
9
|
+
desc "Run all specs"
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
11
|
+
t.rspec_opts = ['-cfs']
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
end
|
15
|
+
|
16
|
+
task :gem do
|
17
|
+
["gem:build", "gem:push"].each do |task|
|
18
|
+
Rake::Task[task].reenable
|
19
|
+
Rake::Task[task].invoke
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
namespace :gem do
|
24
|
+
task :build do
|
25
|
+
sh "gem build restpack-core-client.gemspec"
|
26
|
+
end
|
27
|
+
|
28
|
+
task :push do
|
29
|
+
sh "gem push restpack-core-client-#{RestPack::Core::Client::VERSION}.gem"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RestPack
|
2
|
+
module Core
|
3
|
+
module Client
|
4
|
+
class API
|
5
|
+
def initialize(domain, password)
|
6
|
+
@domain = domain
|
7
|
+
@password = password
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_channel(id)
|
11
|
+
p "API.get_channel(#{id})"
|
12
|
+
json = RestClient.get("http://:#{@password}@#{@domain}/api/v1/channels/#{id}.json")
|
13
|
+
JSON.parse(json, :symbolize_keys => true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_domain(identifier)
|
17
|
+
p "API.get_domain(#{identifier})"
|
18
|
+
json = RestClient.get("http://:#{@password}@#{@domain}/api/v1/domains/search.json?identifier=#{identifier}")
|
19
|
+
result = JSON.parse(json, :symbolize_keys => true)
|
20
|
+
result[:domains].first
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RestPack
|
2
|
+
module Core
|
3
|
+
module Client
|
4
|
+
class Cache
|
5
|
+
def initialize(api)
|
6
|
+
@api = api
|
7
|
+
@domain_to_channel = {}
|
8
|
+
@channels = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.create(domain, password)
|
12
|
+
api = RestPack::Core::Client::API.new(domain, password)
|
13
|
+
Cache.new(api)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_channel(domain_identifier) #TODO: GJ: convert channel response into hierarchical structure
|
17
|
+
domain = get_domain(domain_identifier)
|
18
|
+
@channels[domain[:channel_id]] ||= @api.get_channel(domain[:channel_id])
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_domain(domain_identifier)
|
22
|
+
@domain_to_channel[domain_identifier] ||= @api.get_domain(domain_identifier)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'restpack-core-client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "restpack-core-client"
|
8
|
+
gem.version = RestPack::Core::Client::VERSION
|
9
|
+
gem.authors = ["Gavin Joyce"]
|
10
|
+
gem.email = ["gavinjoyce@gmail.com"]
|
11
|
+
gem.description = %q{A simple client gem for restpack-core-service}
|
12
|
+
gem.summary = %q{A simple client gem for restpack-core-service}
|
13
|
+
gem.homepage = "https://github.com/RestPack"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'rest-client', '~> 1.6.7'
|
21
|
+
gem.add_dependency 'yajl-ruby', '~> 1.1.0'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.12.0'
|
24
|
+
gem.add_development_dependency 'rake', '~> 10.0.3'
|
25
|
+
end
|
data/spec/cache_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'restpack-core-client/cache'
|
3
|
+
|
4
|
+
describe RestPack::Core::Client::Cache do
|
5
|
+
let(:api) { RestPack::Core::Client::API.new('core.internal.domain.ie', 'password') }
|
6
|
+
let(:cache) { RestPack::Core::Client::Cache.new(api) }
|
7
|
+
|
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
|
+
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: restpack-core-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gavin Joyce
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.6.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.7
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: yajl-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.1.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.1.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.12.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.12.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 10.0.3
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 10.0.3
|
78
|
+
description: A simple client gem for restpack-core-service
|
79
|
+
email:
|
80
|
+
- gavinjoyce@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .travis.yml
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/restpack-core-client.rb
|
92
|
+
- lib/restpack-core-client/api.rb
|
93
|
+
- lib/restpack-core-client/cache.rb
|
94
|
+
- lib/restpack-core-client/version.rb
|
95
|
+
- restpack-core-client.gemspec
|
96
|
+
- spec/cache_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
homepage: https://github.com/RestPack
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.24
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: A simple client gem for restpack-core-service
|
122
|
+
test_files:
|
123
|
+
- spec/cache_spec.rb
|
124
|
+
- spec/spec_helper.rb
|