rhogallery 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rhogallery (0.0.1)
4
+ rhogallery (0.1.0)
5
5
  json (~> 1.5.4)
6
6
  rest-client (~> 1.6.6)
7
7
 
data/README.markdown CHANGED
@@ -1,36 +1,36 @@
1
- Rhogallery API
1
+ RhoGallery API
2
2
  ==================
3
- ##Instaling
3
+ ##Getting Started
4
4
 
5
5
  This is a ruby interface to connect with the rhohub rhogallery api.
6
6
 
7
7
  $ gem install rhogallery
8
8
 
9
- require 'rhogallery-api'
9
+ require 'rhogallery'
10
10
 
11
- ##Rhogallery Credentials
11
+ ##RhoGallery Credentials
12
12
 
13
- First of all you need to set your rhogallery credentials (username and rhogallery token):
13
+ First of all you need to set your RhoGallery credentials (username and rhogallery token):
14
14
 
15
- RhoGalleryApi.credentials = {:username => YOUR_RHOHUB_USERNAME, :token => YOUR_RHOHUB_TOKEN}
15
+ RhoGallery.credentials = {:username => YOUR_RHOHUB_USERNAME, :token => YOUR_RHOHUB_TOKEN}
16
16
 
17
17
  Also, you can see your credentials any time with:
18
18
 
19
- RhoGalleryApi.credentials
19
+ RhoGallery.credentials
20
20
  => {:username => YOUR_RHOHUB_USERNAME, :token => YOUR_RHOHUB_TOKEN}
21
21
 
22
- ##Rhogallery Resources
22
+ ##RhoGallery Resources
23
23
 
24
24
  Then you have two classes that you can work with: `RhoGallery::Consumer` and `RhoGallery::Group`
25
25
 
26
- RhoGalleryApi # Rhogallery Api Defaults configurations
26
+ RhoGallery # Rhogallery main module
27
27
 
28
28
  RhoGallery::Consumer
29
29
  RhoGallery::Group
30
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
31
+ create(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
34
 
35
35
  * data: consumer or group data, for example: name, cell, login, email. By default takes the data hash takes the attributes
36
36
  added when is creating the instance ( RhoGallery::Group.new( {:name => "some group name" }) ).
@@ -57,7 +57,7 @@ You can get all your consumers and groups like this:
57
57
 
58
58
  or if you want to find a consumer/group by id you can do this:
59
59
 
60
- RhoGallery::Consumer.find_by_id("some_consumer_id")
60
+ RhoGallery::Consumer.find("some_consumer_id")
61
61
  => {"name":"John Doe","devices":["ios","android","blackberry"],"deactivated_id":null,
62
62
  "created_at":"2011-01-14T17:49:42Z","cell":"+555555",
63
63
  "updated_at":"2011-06-21T21:14:12Z",
@@ -65,7 +65,7 @@ or if you want to find a consumer/group by id you can do this:
65
65
  "login":"john","invited":true,
66
66
  "email":"john@doe.com","active":true}
67
67
 
68
- RhoGallery::Group.find_by_id("some_group_id")
68
+ RhoGallery::Group.find("some_group_id")
69
69
  => {"name":"rhomobile","created_at":"2011-01-14T15:37:42Z","updated_at":"2011-01-14T15:37:42Z",
70
70
  "id":"4d306dc697fcc274a6000009","active":true}
71
71
 
@@ -78,22 +78,22 @@ You can create new groups and consumers with your own attributes and then save i
78
78
  })
79
79
  => #<RhoGallery::Consumer:0x1018881a8 @attributes={:login => "some_login", :name => "some name", :cell => "+55555", :email => "email@email.com"}>
80
80
 
81
- consumer.create_new
81
+ consumer.save
82
82
  => true
83
83
 
84
84
  group = RhoGallery::Group.new({:name => "new_group_name"})
85
85
  => #<RhoGallery::Group:0x1018881b6 @attributes={:name=>"new_group_name"}>
86
86
 
87
- group.create_new
87
+ group.save
88
88
  => true
89
89
 
90
- or send it the data on the `create_new` method is called
90
+ or send the data directly when `create` method is called
91
91
 
92
92
  consumer = RhoGallery::Consumer.new
93
93
  => #<RhoGallery::Consumer:0x1018881a8 @attributes={:cell=>"+55555", :email=>"email@email.com",
94
94
  :login=>"some_login",:tags=>"", :password=>"", :name=>"hello", :id=>"4e60ffd4bdd0c8048c000001"}>
95
95
 
96
- consumer.create_new({
96
+ consumer.create({
97
97
  :login => "some_login", :name => "some name", :cell => "+55555", :email => "email@email.com"
98
98
  })
99
99
  => true
@@ -102,7 +102,7 @@ or send it the data on the `create_new` method is called
102
102
 
103
103
  Also you can update your consumers and groups fields with the `update`
104
104
 
105
- consumer = RhoGallery::Consumer.find_by_id("4e60ffd4bdd0c8048c000001")
105
+ consumer = RhoGallery::Consumer.find("4e60ffd4bdd0c8048c000001")
106
106
  => #<RhoGallery::Consumer:0x1018881a8 @attributes={:cell=>"some_cell_phone", :invited=>false, :email=>"email@email.com",
107
107
  :login=>"some_login",:tags=>"", :password=>"", :name=>"hello", :id=>"4e60ffd4bdd0c8048c000001"}>
108
108
 
@@ -114,7 +114,7 @@ Also you can update your consumers and groups fields with the `update`
114
114
 
115
115
  and you can delete it too :)
116
116
 
117
- consumer = RhoGallery::Consumer.find_by_id("4e60ffd4bdd0c8048c000001")
117
+ consumer = RhoGallery::Consumer.find("4e60ffd4bdd0c8048c000001")
118
118
  => #<RhoGallery::Consumer:0x1018881a8 @attributes={:cell=>"new cell phone", :invited=>false, :email=>"email@email.com",
119
119
  :login=>"new_login",:tags=>"", :password=>"", :name=>"hello", :id=>"4e60ffd4bdd0c8048c000001"}>
120
120
 
@@ -123,11 +123,11 @@ and you can delete it too :)
123
123
 
124
124
  ##See Errors
125
125
 
126
- you can see the errors when the create_new and update methods returns false, with errors method. Example
126
+ You can see the errors when the `create` and `update` methods return false, using the errors method. For example:
127
127
 
128
128
  group = RhoGallery::Group.new
129
129
  => #<RhoGallery::Group:0x1018881c7 @attributes={:name => ""}>
130
- group.create_new
130
+ group.save
131
131
  => false
132
132
 
133
133
  group.errors
data/init.rb CHANGED
@@ -1 +1 @@
1
- require 'rhogallery-api'
1
+ require 'rhogallery'
@@ -19,7 +19,7 @@ class RhoGallery::Base
19
19
  @attributes
20
20
  end
21
21
 
22
- def create_new(data, options, resource)
22
+ def create(data, options, resource)
23
23
  begin
24
24
  RestClient.post RhoGallery.resource_url(options[:username], resource), data, {:Authorization => options[:token]}
25
25
  @errors = String.new
@@ -46,12 +46,16 @@ class RhoGallery::Base
46
46
  true
47
47
  end
48
48
 
49
+ def save(data, options, resource)
50
+ self.id ? update(data, options, "#{resource}/#{self.id}") : create(data, options, resource)
51
+ end
52
+
49
53
  def self.find_all(options, resource)
50
54
  res = RestClient::Resource.new(RhoGallery.resource_url(options[:username], "#{resource}"), :headers => {:Authorization => options[:token]})
51
55
  JSON.parse res.get
52
56
  end
53
57
 
54
- def self.find_by_id(id, options, resource)
58
+ def self.find(id, options, resource)
55
59
  res = RestClient::Resource.new(RhoGallery.resource_url(options[:username], "#{resource}/#{id}"), :headers => {:Authorization => options[:token]})
56
60
  JSON.parse res.get
57
61
  end
@@ -1,12 +1,16 @@
1
1
  class RhoGallery::Consumer < RhoGallery::Base
2
2
 
3
- def create_new(data = @attributes, options = RhoGallery.credentials, resource = "consumers")
3
+ def create(data = @attributes, options = RhoGallery.credentials, resource = "consumers")
4
+ super(data, options, resource)
5
+ end
6
+
7
+ def save(data = @attributes, options = RhoGallery.credentials, resource = "consumers")
4
8
  super(data, options, resource)
5
9
  end
6
10
 
7
11
  def update(data = @attributes, options = RhoGallery.credentials, resource = "consumers/#{self.id}")
8
12
  if super(data, options, resource)
9
- @attributes = RhoGallery::Consumer::find_by_id(self.id, options).get_attributes
13
+ @attributes = RhoGallery::Consumer::find(self.id, options).get_attributes
10
14
  self
11
15
  else
12
16
  false
@@ -17,8 +21,8 @@ class RhoGallery::Consumer < RhoGallery::Base
17
21
  super(options, resource)
18
22
  end
19
23
 
20
- def self.find_by_id(id = "", options = RhoGallery.credentials)
21
- consumer = RhoGallery::Base.find_by_id(id, options, "consumers")
24
+ def self.find(id = "", options = RhoGallery.credentials)
25
+ consumer = RhoGallery::Base.find(id, options, "consumers")
22
26
  RhoGallery::Consumer.new(RhoGallery.prepare_hash(consumer))
23
27
  end
24
28
 
@@ -1,6 +1,10 @@
1
1
  class RhoGallery::Group < RhoGallery::Base
2
2
 
3
- def create_new(data = @attributes, options = RhoGallery.credentials, resource = "groups")
3
+ def create(data = @attributes, options = RhoGallery.credentials, resource = "groups")
4
+ super(data, options, resource)
5
+ end
6
+
7
+ def save(data = @attributes, options = RhoGallery.credentials, resource = "groups")
4
8
  super(data, options, resource)
5
9
  end
6
10
 
@@ -17,8 +21,8 @@ class RhoGallery::Group < RhoGallery::Base
17
21
  groups.collect!{|group| RhoGallery::Group.new(RhoGallery.prepare_hash(group))} unless groups.empty?
18
22
  end
19
23
 
20
- def self.find_by_id(id, options = RhoGallery.credentials)
21
- group = RhoGallery::Base.find_by_id(id, options, "groups")
24
+ def self.find(id, options = RhoGallery.credentials)
25
+ group = RhoGallery::Base.find(id, options, "groups")
22
26
  RhoGallery::Group.new(RhoGallery.prepare_hash(group))
23
27
  end
24
28
 
File without changes
@@ -0,0 +1,3 @@
1
+ module Rhogallery
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rhogallery.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "rubygems"
2
+ require "json"
3
+ require "rest_client"
4
+ require "rhogallery/version"
5
+ require "rhogallery/rho_gallery"
6
+ require "rhogallery/base"
7
+ require "rhogallery/consumer"
8
+ require "rhogallery/group"
9
+ ENV['rhogallery_api_url'] = "https://app.rhohub.com/rhogallery/api/v1/:username/:resource.json"
data/rhogallery.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require 'rhogallery-api/version'
3
+ require 'rhogallery/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "rhogallery"
@@ -14,7 +14,7 @@ describe RhoGallery::Consumer do
14
14
  end
15
15
 
16
16
  it "should make a GET request to get a consumer by ID" do
17
- RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
17
+ RhoGallery::Consumer.find("4e6146d5bdd0c8048c000004")
18
18
  WebMock.should have_requested(:get, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004"))
19
19
  end
20
20
  end
@@ -22,17 +22,17 @@ describe RhoGallery::Consumer do
22
22
  context "Create, update and Delete actions" do
23
23
  it "should send a POST request to save a new consumer" do
24
24
  new_cons = RhoGallery::Consumer.new({:login => "testconsumer", :name => "this is a name"})
25
- new_cons.create_new
25
+ new_cons.save
26
26
  WebMock.should have_requested(:post, RhoGallery.resource_url("testuser", "consumers"))
27
27
  end
28
28
  it "should send a PUT request to update a consumer" do
29
- consumer = RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
29
+ consumer = RhoGallery::Consumer.find("4e6146d5bdd0c8048c000004")
30
30
  consumer.login = "new_login_for_this_consumer"
31
31
  consumer.update
32
32
  WebMock.should have_requested(:put, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004"))
33
33
  end
34
34
  it "should send a DELETE request to delete a consumer" do
35
- consumer = RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
35
+ consumer = RhoGallery::Consumer.find("4e6146d5bdd0c8048c000004")
36
36
  consumer.delete
37
37
  WebMock.should have_requested(:delete, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004"))
38
38
  end
@@ -40,14 +40,14 @@ describe RhoGallery::Consumer do
40
40
  stub_request(:post, RhoGallery.resource_url("testuser", "consumers")).
41
41
  to_return({:status => 422, :body => "login can't be blank"})
42
42
  new_cons = RhoGallery::Consumer.new({:name => "this is a name"})
43
- new_cons.create_new
43
+ new_cons.save
44
44
  WebMock.should have_requested(:post, RhoGallery.resource_url("testuser", "consumers"))
45
45
  new_cons.errors.should == "login can't be blank"
46
46
  end
47
47
  it "should respond with error when is trying to update a consumer with wrong attributes" do
48
48
  stub_request(:put, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004")).
49
49
  to_return({:status => 422, :body => "login can't be blank"})
50
- consumer = RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
50
+ consumer = RhoGallery::Consumer.find("4e6146d5bdd0c8048c000004")
51
51
  consumer.login = ""
52
52
  consumer.update
53
53
  WebMock.should have_requested(:put, RhoGallery.resource_url("testuser", "consumers/4e6146d5bdd0c8048c000004"))
@@ -57,7 +57,7 @@ describe RhoGallery::Consumer do
57
57
 
58
58
  context "Get and set consumers values" do
59
59
  before(:each) do
60
- @consumer = RhoGallery::Consumer.find_by_id("4e6146d5bdd0c8048c000004")
60
+ @consumer = RhoGallery::Consumer.find("4e6146d5bdd0c8048c000004")
61
61
  end
62
62
 
63
63
  it "should get the consumer values and set new values" do
data/spec/group_spec.rb CHANGED
@@ -14,7 +14,7 @@ describe RhoGallery::Group do
14
14
  end
15
15
 
16
16
  it "should make a GET request when is finding a group by ID" do
17
- RhoGallery::Group.find_by_id("4e6146d5bdd0c8048c000004")
17
+ RhoGallery::Group.find("4e6146d5bdd0c8048c000004")
18
18
  WebMock.should have_requested(:get, RhoGallery.resource_url("testuser", "groups/4e6146d5bdd0c8048c000004"))
19
19
  end
20
20
  end
@@ -22,11 +22,11 @@ describe RhoGallery::Group do
22
22
  context "Create and delete actions" do
23
23
  it "should send a POST request when is creating a new group" do
24
24
  new_group = RhoGallery::Group.new({:name => "group_name"})
25
- new_group.create_new()
25
+ new_group.save
26
26
  WebMock.should have_requested(:post, RhoGallery.resource_url("testuser", "groups"))
27
27
  end
28
28
  it "should send a DELETE request when is deleting a group" do
29
- group = RhoGallery::Group.find_by_id("4e6146d5bdd0c8048c000004")
29
+ group = RhoGallery::Group.find("4e6146d5bdd0c8048c000004")
30
30
  group.delete
31
31
  WebMock.should have_requested(:delete, RhoGallery.resource_url("testuser", "groups/4e6146d5bdd0c8048c000004"))
32
32
  end
@@ -34,7 +34,7 @@ describe RhoGallery::Group do
34
34
  stub_request(:post, RhoGallery.resource_url("testuser", "groups")).
35
35
  to_return({:status => 422, :body => "name can't be blank"})
36
36
  new_group = RhoGallery::Group.new
37
- new_group.create_new
37
+ new_group.save
38
38
  WebMock.should have_requested(:post, RhoGallery.resource_url("testuser", "groups"))
39
39
  new_group.errors.should == "name can't be blank"
40
40
  end
@@ -42,7 +42,7 @@ describe RhoGallery::Group do
42
42
 
43
43
  context "Get groups values" do
44
44
  it "should get al the group values" do
45
- group = RhoGallery::Group.find_by_id("4e6146d5bdd0c8048c000004")
45
+ group = RhoGallery::Group.find("4e6146d5bdd0c8048c000004")
46
46
  group.name.should == "koombea"
47
47
  group.id.should == "4e6146d5bdd0c8048c000004"
48
48
  end
@@ -50,7 +50,7 @@ describe RhoGallery::Group do
50
50
 
51
51
  context "Update method doesn't exist for groups" do
52
52
  it "should raise a NotMethod Exception when is trying to update a group" do
53
- group = RhoGallery::Group.find_by_id("4e6146d5bdd0c8048c000004")
53
+ group = RhoGallery::Group.find("4e6146d5bdd0c8048c000004")
54
54
  lambda { group.update }.should raise_error
55
55
  end
56
56
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require 'rhogallery-api'
2
+ require 'rhogallery'
3
3
  require 'rspec'
4
4
  require 'webmock/rspec'
5
5
  include WebMock::API
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhogallery
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rhomobile
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-22 00:00:00 Z
18
+ date: 2011-09-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
@@ -65,12 +65,12 @@ files:
65
65
  - README.markdown
66
66
  - Rakefile
67
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
68
+ - lib/rhogallery.rb
69
+ - lib/rhogallery/base.rb
70
+ - lib/rhogallery/consumer.rb
71
+ - lib/rhogallery/group.rb
72
+ - lib/rhogallery/rho_gallery.rb
73
+ - lib/rhogallery/version.rb
74
74
  - rhogallery.gemspec
75
75
  - spec/consumer_spec.rb
76
76
  - spec/group_spec.rb
@@ -1,3 +0,0 @@
1
- module Rhogallery
2
- VERSION = "0.0.1"
3
- end
@@ -1,9 +0,0 @@
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"