rhogallery 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +42 -0
- data/README.markdown +139 -0
- data/Rakefile +23 -0
- data/init.rb +1 -0
- data/lib/rhogallery-api/base.rb +78 -0
- data/lib/rhogallery-api/consumer.rb +30 -0
- data/lib/rhogallery-api/group.rb +25 -0
- data/lib/rhogallery-api/rho_gallery.rb +32 -0
- data/lib/rhogallery-api/version.rb +3 -0
- data/lib/rhogallery-api.rb +9 -0
- data/rhogallery.gemspec +27 -0
- data/spec/consumer_spec.rb +72 -0
- data/spec/group_spec.rb +57 -0
- data/spec/rho_gallery_spec.rb +17 -0
- data/spec/spec_helper.rb +49 -0
- metadata +116 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rhogallery (0.0.1)
|
5
|
+
json (~> 1.5.4)
|
6
|
+
rest-client (~> 1.6.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.2.6)
|
12
|
+
crack (0.1.8)
|
13
|
+
diff-lcs (1.1.2)
|
14
|
+
json (1.5.4)
|
15
|
+
mime-types (1.16)
|
16
|
+
rake (0.9.2)
|
17
|
+
rcov (0.9.10)
|
18
|
+
rest-client (1.6.6)
|
19
|
+
mime-types (>= 1.16)
|
20
|
+
rspec (2.5.0)
|
21
|
+
rspec-core (~> 2.5.0)
|
22
|
+
rspec-expectations (~> 2.5.0)
|
23
|
+
rspec-mocks (~> 2.5.0)
|
24
|
+
rspec-core (2.5.2)
|
25
|
+
rspec-expectations (2.5.0)
|
26
|
+
diff-lcs (~> 1.1.2)
|
27
|
+
rspec-mocks (2.5.0)
|
28
|
+
webmock (1.7.4)
|
29
|
+
addressable (> 2.2.5, ~> 2.2)
|
30
|
+
crack (>= 0.1.7)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
json
|
37
|
+
rake
|
38
|
+
rcov (~> 0.9.8)
|
39
|
+
rest-client
|
40
|
+
rhogallery!
|
41
|
+
rspec (~> 2.5.0)
|
42
|
+
webmock
|
data/README.markdown
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
Rhogallery API
|
2
|
+
==================
|
3
|
+
##Instaling
|
4
|
+
|
5
|
+
This is a ruby interface to connect with the rhohub rhogallery api.
|
6
|
+
|
7
|
+
$ gem install rhogallery
|
8
|
+
|
9
|
+
require 'rhogallery-api'
|
10
|
+
|
11
|
+
##Rhogallery Credentials
|
12
|
+
|
13
|
+
First of all you need to set your rhogallery credentials (username and rhogallery token):
|
14
|
+
|
15
|
+
RhoGalleryApi.credentials = {:username => YOUR_RHOHUB_USERNAME, :token => YOUR_RHOHUB_TOKEN}
|
16
|
+
|
17
|
+
Also, you can see your credentials any time with:
|
18
|
+
|
19
|
+
RhoGalleryApi.credentials
|
20
|
+
=> {:username => YOUR_RHOHUB_USERNAME, :token => YOUR_RHOHUB_TOKEN}
|
21
|
+
|
22
|
+
##Rhogallery Resources
|
23
|
+
|
24
|
+
Then you have two classes that you can work with: `RhoGallery::Consumer` and `RhoGallery::Group`
|
25
|
+
|
26
|
+
RhoGalleryApi # Rhogallery Api Defaults configurations
|
27
|
+
|
28
|
+
RhoGallery::Consumer
|
29
|
+
RhoGallery::Group
|
30
|
+
|
31
|
+
create_new(data, options) #create a new consumer/group
|
32
|
+
update(data, options) #use this method to update data
|
33
|
+
delete(data, options) #to delete a consumer/group
|
34
|
+
|
35
|
+
* data: consumer or group data, for example: name, cell, login, email. By default takes the data hash takes the attributes
|
36
|
+
added when is creating the instance ( RhoGallery::Group.new( {:name => "some group name" }) ).
|
37
|
+
|
38
|
+
* options: credentials options, you can use a diferent credential in any time.
|
39
|
+
|
40
|
+
##Get Consumers and Groups
|
41
|
+
|
42
|
+
You can get all your consumers and groups like this:
|
43
|
+
|
44
|
+
RhoGallery::Consumer.find_all
|
45
|
+
=> [{"name":"John Doe","devices":["ios","android","blackberry"],"deactivated_id":null,
|
46
|
+
"created_at":"2011-01-14T17:49:42Z","cell":"+555555",
|
47
|
+
"updated_at":"2011-06-21T21:14:12Z",
|
48
|
+
"tags":"","deleted":false,"password":"f3df5b5853c26e9b664262a5f590df8d",
|
49
|
+
"login":"john","invited":true,
|
50
|
+
"email":"john@doe.com","active":true}]
|
51
|
+
|
52
|
+
RhoGallery::Group.find_all
|
53
|
+
=> [{"name":"rhomobile","created_at":"2011-01-14T15:37:42Z","updated_at":"2011-01-14T15:37:42Z",
|
54
|
+
"id":"4d306dc697fcc274a6000009","active":true},
|
55
|
+
{"name":"koombea","created_at":"2011-05-27T22:24:05Z","updated_at":"2011-05-27T22:24:05Z",
|
56
|
+
"id":"4de024851189870001000001","active":true}]
|
57
|
+
|
58
|
+
or if you want to find a consumer/group by id you can do this:
|
59
|
+
|
60
|
+
RhoGallery::Consumer.find_by_id("some_consumer_id")
|
61
|
+
=> {"name":"John Doe","devices":["ios","android","blackberry"],"deactivated_id":null,
|
62
|
+
"created_at":"2011-01-14T17:49:42Z","cell":"+555555",
|
63
|
+
"updated_at":"2011-06-21T21:14:12Z",
|
64
|
+
"tags":"","deleted":false,"password":"f3df5b5853c26e9b664262a5f590df8d",
|
65
|
+
"login":"john","invited":true,
|
66
|
+
"email":"john@doe.com","active":true}
|
67
|
+
|
68
|
+
RhoGallery::Group.find_by_id("some_group_id")
|
69
|
+
=> {"name":"rhomobile","created_at":"2011-01-14T15:37:42Z","updated_at":"2011-01-14T15:37:42Z",
|
70
|
+
"id":"4d306dc697fcc274a6000009","active":true}
|
71
|
+
|
72
|
+
##Create new consumer/group
|
73
|
+
|
74
|
+
You can create new groups and consumers with your own attributes and then save it as a new consumer/group. (returns true or false).
|
75
|
+
|
76
|
+
consumer = RhoGallery::Consumer.new({
|
77
|
+
:login => "some_login", :name => "some name", :cell => "+55555", :email => "email@email.com"
|
78
|
+
})
|
79
|
+
=> #<RhoGallery::Consumer:0x1018881a8 @attributes={:login => "some_login", :name => "some name", :cell => "+55555", :email => "email@email.com"}>
|
80
|
+
|
81
|
+
consumer.create_new
|
82
|
+
=> true
|
83
|
+
|
84
|
+
group = RhoGallery::Group.new({:name => "new_group_name"})
|
85
|
+
=> #<RhoGallery::Group:0x1018881b6 @attributes={:name=>"new_group_name"}>
|
86
|
+
|
87
|
+
group.create_new
|
88
|
+
=> true
|
89
|
+
|
90
|
+
or send it the data on the `create_new` method is called
|
91
|
+
|
92
|
+
consumer = RhoGallery::Consumer.new
|
93
|
+
=> #<RhoGallery::Consumer:0x1018881a8 @attributes={:cell=>"+55555", :email=>"email@email.com",
|
94
|
+
:login=>"some_login",:tags=>"", :password=>"", :name=>"hello", :id=>"4e60ffd4bdd0c8048c000001"}>
|
95
|
+
|
96
|
+
consumer.create_new({
|
97
|
+
:login => "some_login", :name => "some name", :cell => "+55555", :email => "email@email.com"
|
98
|
+
})
|
99
|
+
=> true
|
100
|
+
|
101
|
+
##Update Method
|
102
|
+
|
103
|
+
Also you can update your consumers and groups fields with the `update`
|
104
|
+
|
105
|
+
consumer = RhoGallery::Consumer.find_by_id("4e60ffd4bdd0c8048c000001")
|
106
|
+
=> #<RhoGallery::Consumer:0x1018881a8 @attributes={:cell=>"some_cell_phone", :invited=>false, :email=>"email@email.com",
|
107
|
+
:login=>"some_login",:tags=>"", :password=>"", :name=>"hello", :id=>"4e60ffd4bdd0c8048c000001"}>
|
108
|
+
|
109
|
+
consumer.update({:login => "new_login", :cell => "new cell phone"})
|
110
|
+
=> #<RhoGallery::Consumer:0x1018881a8 @attributes={:cell=>"new cell phone", :invited=>false, :email=>"email@email.com",
|
111
|
+
:login=>"new_login",:tags=>"", :password=>"", :name=>"hello", :id=>"4e60ffd4bdd0c8048c000001"}>
|
112
|
+
|
113
|
+
##Delete a Consumer or Group
|
114
|
+
|
115
|
+
and you can delete it too :)
|
116
|
+
|
117
|
+
consumer = RhoGallery::Consumer.find_by_id("4e60ffd4bdd0c8048c000001")
|
118
|
+
=> #<RhoGallery::Consumer:0x1018881a8 @attributes={:cell=>"new cell phone", :invited=>false, :email=>"email@email.com",
|
119
|
+
:login=>"new_login",:tags=>"", :password=>"", :name=>"hello", :id=>"4e60ffd4bdd0c8048c000001"}>
|
120
|
+
|
121
|
+
consumer.delete
|
122
|
+
=> true
|
123
|
+
|
124
|
+
##See Errors
|
125
|
+
|
126
|
+
you can see the errors when the create_new and update methods returns false, with errors method. Example
|
127
|
+
|
128
|
+
group = RhoGallery::Group.new
|
129
|
+
=> #<RhoGallery::Group:0x1018881c7 @attributes={:name => ""}>
|
130
|
+
group.create_new
|
131
|
+
=> false
|
132
|
+
|
133
|
+
group.errors
|
134
|
+
=> "Name can't be blank"
|
135
|
+
|
136
|
+
##Meta
|
137
|
+
Created and maintained by [Luis Manotas](https://github.com/lmanotas), [Mario Tatis](https://github.com/mariotatis) and [Lars Burgess](https://github.com/larsburgess).
|
138
|
+
|
139
|
+
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
Bundler.setup(:default, :test)
|
6
|
+
|
7
|
+
require 'bundler/gem_tasks'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
desc "Run all specs"
|
11
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
12
|
+
t.rspec_opts = ["-b", "-c", "-fd"]
|
13
|
+
t.pattern = 'spec/**/*_spec.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Run all specs with rcov"
|
17
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
18
|
+
t.rcov = true
|
19
|
+
t.rspec_opts = ["-b", "-c", "-fd"]
|
20
|
+
t.rcov_opts = ['--exclude', 'spec/*,gems/*']
|
21
|
+
end
|
22
|
+
|
23
|
+
task :default => :spec
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rhogallery-api'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class RhoGallery::Base
|
2
|
+
|
3
|
+
def initialize(data = {})
|
4
|
+
@attributes = data
|
5
|
+
@errors = String.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def id
|
9
|
+
@attributes[:id]
|
10
|
+
end
|
11
|
+
|
12
|
+
def errors
|
13
|
+
@errors.strip
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def get_attributes
|
19
|
+
@attributes
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_new(data, options, resource)
|
23
|
+
begin
|
24
|
+
RestClient.post RhoGallery.resource_url(options[:username], resource), data, {:Authorization => options[:token]}
|
25
|
+
@errors = String.new
|
26
|
+
true
|
27
|
+
rescue RestClient::RequestFailed => e
|
28
|
+
@errors = e.response.body
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def update(data, options, resource)
|
34
|
+
begin
|
35
|
+
RestClient.put RhoGallery.resource_url(options[:username], resource), data, {:Authorization => options[:token]}
|
36
|
+
true
|
37
|
+
@errors = String.new
|
38
|
+
rescue RestClient::RequestFailed => e
|
39
|
+
@errors = e.response.body
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete(options, resource)
|
45
|
+
RestClient.delete RhoGallery.resource_url(options[:username], resource), {:Authorization => options[:token]}
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.find_all(options, resource)
|
50
|
+
res = RestClient::Resource.new(RhoGallery.resource_url(options[:username], "#{resource}"), :headers => {:Authorization => options[:token]})
|
51
|
+
JSON.parse res.get
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.find_by_id(id, options, resource)
|
55
|
+
res = RestClient::Resource.new(RhoGallery.resource_url(options[:username], "#{resource}/#{id}"), :headers => {:Authorization => options[:token]})
|
56
|
+
JSON.parse res.get
|
57
|
+
end
|
58
|
+
|
59
|
+
def method_missing(method_sym, *arguments, &block)
|
60
|
+
@attributes = RhoGallery.prepare_hash(@attributes)
|
61
|
+
if method_sym.to_s.slice("=")
|
62
|
+
att = method_sym.to_s.split("=").first.strip
|
63
|
+
if @attributes[att.to_sym]
|
64
|
+
@attributes[att.to_sym] = arguments.to_s
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
68
|
+
else
|
69
|
+
att = @attributes[method_sym]
|
70
|
+
if att
|
71
|
+
att
|
72
|
+
else
|
73
|
+
super
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class RhoGallery::Consumer < RhoGallery::Base
|
2
|
+
|
3
|
+
def create_new(data = @attributes, options = RhoGallery.credentials, resource = "consumers")
|
4
|
+
super(data, options, resource)
|
5
|
+
end
|
6
|
+
|
7
|
+
def update(data = @attributes, options = RhoGallery.credentials, resource = "consumers/#{self.id}")
|
8
|
+
if super(data, options, resource)
|
9
|
+
@attributes = RhoGallery::Consumer::find_by_id(self.id, options).get_attributes
|
10
|
+
self
|
11
|
+
else
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete(options = RhoGallery.credentials, resource = "consumers/#{self.id}")
|
17
|
+
super(options, resource)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find_by_id(id = "", options = RhoGallery.credentials)
|
21
|
+
consumer = RhoGallery::Base.find_by_id(id, options, "consumers")
|
22
|
+
RhoGallery::Consumer.new(RhoGallery.prepare_hash(consumer))
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find_all(options = RhoGallery.credentials)
|
26
|
+
consumers = RhoGallery::Base.find_all(options, "consumers")
|
27
|
+
consumers.collect!{|consumer| RhoGallery::Consumer.new(RhoGallery.prepare_hash(consumer))} unless consumers.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class RhoGallery::Group < RhoGallery::Base
|
2
|
+
|
3
|
+
def create_new(data = @attributes, options = RhoGallery.credentials, resource = "groups")
|
4
|
+
super(data, options, resource)
|
5
|
+
end
|
6
|
+
|
7
|
+
def update(data = @attributes, options = RhoGallery.credentials)
|
8
|
+
method_missing(:update)
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(options = RhoGallery.credentials, resource = "groups/#{self.id}")
|
12
|
+
super(options, resource)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find_all(options = RhoGallery.credentials)
|
16
|
+
groups = RhoGallery::Base.find_all(options, "groups")
|
17
|
+
groups.collect!{|group| RhoGallery::Group.new(RhoGallery.prepare_hash(group))} unless groups.empty?
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find_by_id(id, options = RhoGallery.credentials)
|
21
|
+
group = RhoGallery::Base.find_by_id(id, options, "groups")
|
22
|
+
RhoGallery::Group.new(RhoGallery.prepare_hash(group))
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RhoGallery
|
2
|
+
|
3
|
+
def self.credentials=(user_credentials)
|
4
|
+
user_credentials = prepare_hash(user_credentials)
|
5
|
+
if user_credentials[:username] and user_credentials[:token]
|
6
|
+
ENV['rhogallery_username'] = user_credentials[:username]
|
7
|
+
ENV['rhogallery_token'] = user_credentials[:token]
|
8
|
+
else
|
9
|
+
raise "Invalid RhoGallery credentials. correct format: {:username => 'your username', :token => 'your rhogallery token'}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.credentials
|
14
|
+
if ENV['rhogallery_username'] and ENV['rhogallery_token']
|
15
|
+
{:username => ENV['rhogallery_username'], :token => ENV['rhogallery_token']}
|
16
|
+
else
|
17
|
+
raise "You must set up your rhogallery credentials see README file"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.resource_url(username = ENV['rhogallery_username'], resource = "")
|
22
|
+
base_url = ENV['rhogallery_api_url'].gsub(/:username/, username)
|
23
|
+
base_url.gsub(/:resource/, resource)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.prepare_hash(data_parsed)
|
27
|
+
data = {}
|
28
|
+
data_parsed.each{|k,v| data.merge!({k.to_sym => v})}
|
29
|
+
data
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "json"
|
3
|
+
require "rest_client"
|
4
|
+
require "rhogallery-api/version"
|
5
|
+
require "rhogallery-api/rho_gallery"
|
6
|
+
require "rhogallery-api/base"
|
7
|
+
require "rhogallery-api/consumer"
|
8
|
+
require "rhogallery-api/group"
|
9
|
+
ENV['rhogallery_api_url'] = "https://appstaging.rhohub.com/rhogallery/api/v1/:username/:resource.json"
|
data/rhogallery.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'rhogallery-api/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rhogallery"
|
7
|
+
s.version = Rhogallery::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Rhomobile"]
|
10
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
11
|
+
s.email = ["support@rhomobile.com"]
|
12
|
+
s.homepage = %q{http://rhomobile.com}
|
13
|
+
s.summary = %q{RhoGallery client}
|
14
|
+
s.description = %q{RhoGallery api client }
|
15
|
+
|
16
|
+
s.rubyforge_project = nil
|
17
|
+
s.add_dependency('json', '~>1.5.4')
|
18
|
+
s.add_dependency('rest-client', '~>1.6.6')
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
|
25
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe RhoGallery::Consumer do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@spec_helpers = SpecHelpers.new
|
7
|
+
@spec_helpers.stub_consumers_methods
|
8
|
+
end
|
9
|
+
|
10
|
+
context "GET request" do
|
11
|
+
it "should make a GET request to get all the consumers" do
|
12
|
+
RhoGallery::Consumer.find_all
|
13
|
+
WebMock.should have_requested(:get, RhoGallery.resource_url("testuser", "consumers"))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should make a GET request to get a consumer by ID" do
|
17
|
+
RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
|
18
|
+
WebMock.should have_requested(:get, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004"))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "Create, update and Delete actions" do
|
23
|
+
it "should send a POST request to save a new consumer" do
|
24
|
+
new_cons = RhoGallery::Consumer.new({:login => "testconsumer", :name => "this is a name"})
|
25
|
+
new_cons.create_new
|
26
|
+
WebMock.should have_requested(:post, RhoGallery.resource_url("testuser", "consumers"))
|
27
|
+
end
|
28
|
+
it "should send a PUT request to update a consumer" do
|
29
|
+
consumer = RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
|
30
|
+
consumer.login = "new_login_for_this_consumer"
|
31
|
+
consumer.update
|
32
|
+
WebMock.should have_requested(:put, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004"))
|
33
|
+
end
|
34
|
+
it "should send a DELETE request to delete a consumer" do
|
35
|
+
consumer = RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
|
36
|
+
consumer.delete
|
37
|
+
WebMock.should have_requested(:delete, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004"))
|
38
|
+
end
|
39
|
+
it "should respond with error when is trying to create a consumer with wrong attributes" do
|
40
|
+
stub_request(:post, RhoGallery.resource_url("testuser", "consumers")).
|
41
|
+
to_return({:status => 422, :body => "login can't be blank"})
|
42
|
+
new_cons = RhoGallery::Consumer.new({:name => "this is a name"})
|
43
|
+
new_cons.create_new
|
44
|
+
WebMock.should have_requested(:post, RhoGallery.resource_url("testuser", "consumers"))
|
45
|
+
new_cons.errors.should == "login can't be blank"
|
46
|
+
end
|
47
|
+
it "should respond with error when is trying to update a consumer with wrong attributes" do
|
48
|
+
stub_request(:put, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004")).
|
49
|
+
to_return({:status => 422, :body => "login can't be blank"})
|
50
|
+
consumer = RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
|
51
|
+
consumer.login = ""
|
52
|
+
consumer.update
|
53
|
+
WebMock.should have_requested(:put, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004"))
|
54
|
+
consumer.errors.should == "login can't be blank"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "Get and set consumers values" do
|
59
|
+
before(:each) do
|
60
|
+
@consumer = RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should get the consumer values and set new values" do
|
64
|
+
@consumer.login.should == "some_login"
|
65
|
+
@consumer.login = "the_new_login"
|
66
|
+
@consumer.login.should == "the_new_login"
|
67
|
+
end
|
68
|
+
it "should raise an error when an set attribute doesn't exist" do
|
69
|
+
lambda { @consumer.wrong_attribute = "some value" }.should raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/spec/group_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe RhoGallery::Group do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@spec_helpers = SpecHelpers.new
|
7
|
+
@spec_helpers.stub_groups_methods
|
8
|
+
end
|
9
|
+
|
10
|
+
context "GET requests" do
|
11
|
+
it "should send a GET request when is trying to find all the groups" do
|
12
|
+
RhoGallery::Group.find_all
|
13
|
+
WebMock.should have_requested(:get, RhoGallery.resource_url("testuser", "groups"))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should make a GET request when is finding a group by ID" do
|
17
|
+
RhoGallery::Group.find_by_id("4e6146d5bdd0c8048c000004")
|
18
|
+
WebMock.should have_requested(:get, RhoGallery.resource_url("testuser", "groups/4e6146d5bdd0c8048c000004"))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "Create and delete actions" do
|
23
|
+
it "should send a POST request when is creating a new group" do
|
24
|
+
new_group = RhoGallery::Group.new({:name => "group_name"})
|
25
|
+
new_group.create_new()
|
26
|
+
WebMock.should have_requested(:post, RhoGallery.resource_url("testuser", "groups"))
|
27
|
+
end
|
28
|
+
it "should send a DELETE request when is deleting a group" do
|
29
|
+
group = RhoGallery::Group.find_by_id("4e6146d5bdd0c8048c000004")
|
30
|
+
group.delete
|
31
|
+
WebMock.should have_requested(:delete, RhoGallery.resource_url("testuser", "groups/4e6146d5bdd0c8048c000004"))
|
32
|
+
end
|
33
|
+
it "should not create the group wihout name and get the errors" do
|
34
|
+
stub_request(:post, RhoGallery.resource_url("testuser", "groups")).
|
35
|
+
to_return({:status => 422, :body => "name can't be blank"})
|
36
|
+
new_group = RhoGallery::Group.new
|
37
|
+
new_group.create_new
|
38
|
+
WebMock.should have_requested(:post, RhoGallery.resource_url("testuser", "groups"))
|
39
|
+
new_group.errors.should == "name can't be blank"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "Get groups values" do
|
44
|
+
it "should get al the group values" do
|
45
|
+
group = RhoGallery::Group.find_by_id("4e6146d5bdd0c8048c000004")
|
46
|
+
group.name.should == "koombea"
|
47
|
+
group.id.should == "4e6146d5bdd0c8048c000004"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "Update method doesn't exist for groups" do
|
52
|
+
it "should raise a NotMethod Exception when is trying to update a group" do
|
53
|
+
group = RhoGallery::Group.find_by_id("4e6146d5bdd0c8048c000004")
|
54
|
+
lambda { group.update }.should raise_error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe RhoGallery do
|
4
|
+
context "RhoGallery Credentials" do
|
5
|
+
it "should set a user credentials with credentuals method" do
|
6
|
+
RhoGallery.credentials = {:username => "some_username", :token => "some_rhogallery_token"}
|
7
|
+
ENV['rhogallery_username'].should == "some_username"
|
8
|
+
ENV['rhogallery_token'].should == "some_rhogallery_token"
|
9
|
+
end
|
10
|
+
it "should not set and raise an error when is trying to set invalid credentials" do
|
11
|
+
lambda { RhoGallery.credentials = {} }.should raise_error
|
12
|
+
ENV['rhogallery_username'] = nil
|
13
|
+
ENV['rhogallery_token'] = nil
|
14
|
+
lambda { RhoGallery.credentials }.should raise_error
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require 'rhogallery-api'
|
3
|
+
require 'rspec'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
include WebMock::API
|
6
|
+
|
7
|
+
class SpecHelpers
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
ENV['rhogallery_username'] = "testuser"
|
11
|
+
ENV['rhogallery_token'] = "some_uuid_token"
|
12
|
+
WebMock.disable_net_connect!
|
13
|
+
#gorups collection
|
14
|
+
@rhomobile_group = ({:name => "rhomobile", :id => "4e6146d5bdd0c8048c000005"})
|
15
|
+
@koombea_group = ({:name => "koombea", :id => "4e6146d5bdd0c8048c000004"})
|
16
|
+
#consumers collection
|
17
|
+
@rho_consumer = ({:login => "some_login", :name => "rhohub consumer", :cell => "55555", :email => "email@rhohub.com",
|
18
|
+
:id => "4e6146d5bdd0c8048c000004"})
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_groups_methods
|
22
|
+
stub_request(:get, RhoGallery.resource_url("testuser", "groups")).
|
23
|
+
to_return({:body => [@rhomobile_group, @koombea_group].to_json})
|
24
|
+
stub_request(:get, RhoGallery.resource_url("testuser", "groups/4e6146d5bdd0c8048c000004")).
|
25
|
+
to_return({:body => @koombea_group.to_json})
|
26
|
+
stub_request(:post, RhoGallery.resource_url("testuser", "groups")).
|
27
|
+
to_return({:status => 201, :body => "true"})
|
28
|
+
stub_request(:delete, RhoGallery.resource_url("testuser", "groups/4e6146d5bdd0c8048c000004")).
|
29
|
+
to_return({:body => "true", :status => 200})
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_consumers_methods
|
33
|
+
stub_request(:get, RhoGallery.resource_url("testuser", "consumers")).
|
34
|
+
to_return({:body => [@rho_consumer].to_json})
|
35
|
+
stub_request(:get, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004")).
|
36
|
+
to_return({:body => @rho_consumer.to_json})
|
37
|
+
stub_request(:post, RhoGallery.resource_url("testuser", "consumers")).
|
38
|
+
to_return({:status => 201, :body => "true"})
|
39
|
+
stub_request(:put, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004")).
|
40
|
+
to_return({:body => "true", :status => 200})
|
41
|
+
stub_request(:delete, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004")).
|
42
|
+
to_return({:body => "true", :status => 200})
|
43
|
+
end
|
44
|
+
|
45
|
+
def groups_objects
|
46
|
+
[RhoGallery::Group.new(@rhomobile_group), RhoGallery::Group.new(@koombea_group)]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rhogallery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Rhomobile
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-22 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 11
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 5
|
32
|
+
- 4
|
33
|
+
version: 1.5.4
|
34
|
+
version_requirements: *id001
|
35
|
+
name: json
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 6
|
48
|
+
- 6
|
49
|
+
version: 1.6.6
|
50
|
+
version_requirements: *id002
|
51
|
+
name: rest-client
|
52
|
+
description: "RhoGallery api client "
|
53
|
+
email:
|
54
|
+
- support@rhomobile.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- README.markdown
|
66
|
+
- Rakefile
|
67
|
+
- init.rb
|
68
|
+
- lib/rhogallery-api.rb
|
69
|
+
- lib/rhogallery-api/base.rb
|
70
|
+
- lib/rhogallery-api/consumer.rb
|
71
|
+
- lib/rhogallery-api/group.rb
|
72
|
+
- lib/rhogallery-api/rho_gallery.rb
|
73
|
+
- lib/rhogallery-api/version.rb
|
74
|
+
- rhogallery.gemspec
|
75
|
+
- spec/consumer_spec.rb
|
76
|
+
- spec/group_spec.rb
|
77
|
+
- spec/rho_gallery_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
homepage: http://rhomobile.com
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.10
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: RhoGallery client
|
112
|
+
test_files:
|
113
|
+
- spec/consumer_spec.rb
|
114
|
+
- spec/group_spec.rb
|
115
|
+
- spec/rho_gallery_spec.rb
|
116
|
+
- spec/spec_helper.rb
|