mambanation 0.0.3 → 0.0.5

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.
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+
3
+ class HTTPAuthTest < Test::Unit::TestCase
4
+ context "Creating new instance" do
5
+ should "should take user and password" do
6
+ mambanation = MambaNation::HTTPAuth.new('username', 'password')
7
+ mambanation.username.should == 'username'
8
+ mambanation.password.should == 'password'
9
+ end
10
+
11
+ should "accept options" do
12
+ mambanation = MambaNation::HTTPAuth.new('username', 'password', :ssl => true)
13
+ mambanation.options.should == {:ssl => true}
14
+ end
15
+
16
+ should "default ssl to false" do
17
+ mambanation = MambaNation::HTTPAuth.new('username', 'password')
18
+ mambanation.options[:ssl].should be(false)
19
+ end
20
+
21
+ should "use https if ssl is true" do
22
+ MambaNation::HTTPAuth.expects(:base_uri).with('https://api.mambanation.com/v' + MambaNation::API_VERSION)
23
+ mambanation = MambaNation::HTTPAuth.new('username', 'password', :ssl => true)
24
+ end
25
+
26
+ should "use http if ssl is false" do
27
+ MambaNation::HTTPAuth.expects(:base_uri).with('http://api.mambanation.com/v' + MambaNation::API_VERSION)
28
+ mambanation = MambaNation::HTTPAuth.new('username', 'password', :ssl => false)
29
+ end
30
+
31
+ should "use api version if provided" do
32
+ MambaNation::HTTPAuth.expects(:base_uri).with('http://api.mambanation.com/v2')
33
+ mambanation = MambaNation::HTTPAuth.new('username', 'password', {:ssl => false, :api_version => 2})
34
+ end
35
+
36
+ should "not use api versioning if api_version is false " do
37
+ MambaNation::HTTPAuth.expects(:base_uri).with('http://api.mambanation.com/v2')
38
+ mambanation = MambaNation::HTTPAuth.new('username', 'password', {:ssl => false, :api_version => false})
39
+ end
40
+ end
41
+
42
+ context "Client methods" do
43
+ setup do
44
+ @mambanation = MambaNation::HTTPAuth.new('username', 'password')
45
+ end
46
+
47
+ should "not throw error when accessing response message" do
48
+ stub_get('http://api.mambanation.com/users/4.json', 'user.json')
49
+ response = @mambanation.get('/users/4.json')
50
+ response.message.should == 'OK'
51
+ end
52
+
53
+ should "be able to get" do
54
+ stub_get('http://username:password@api.mambanation.com/users/4.json', 'user.json')
55
+ response = @mambanation.get('/users/4.json')
56
+ response.should == fixture_file('user.json')
57
+ end
58
+
59
+ should "be able to get with headers" do
60
+ @mambanation.class.expects(:get).with(
61
+ '/users/4.json', {
62
+ :basic_auth => {:username => 'username', :password => 'password'},
63
+ :headers => {'Foo' => 'Bar'}
64
+ }
65
+ ).returns(fixture_file('user.json'))
66
+ @mambanation.get('/users/4.json', {'Foo' => 'Bar'})
67
+ end
68
+
69
+ should "be able to post" do
70
+ stub_post('http://username:password@api.mambanation.com/users/4.json', 'user.json')
71
+ response = @mambanation.post('/users/4.json', :text => 'My update.')
72
+ response.should == fixture_file('user.json')
73
+ end
74
+
75
+ should "be able to post with headers" do
76
+ @mambanation.class.expects(:post).with(
77
+ '/users/4.json', {
78
+ :headers => {'Foo' => 'Bar'},
79
+ :body => {:text => 'My update.'},
80
+ :basic_auth => {:username => 'username', :password => 'password'}
81
+ }
82
+ ).returns(fixture_file('user.json'))
83
+ @mambanation.post('/user/4.json', {:text => 'My update.'}, {'Foo' => 'Bar'})
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,112 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class RequestTest < Test::Unit::TestCase
4
+ # context "new get request" do
5
+ # setup do
6
+ # @client = mock('mambanation client')
7
+ # @request = MambaNation::Request.new(@client, :get, '/1/statuses/user_timeline.json', {:query => {:since_id => 1234}})
8
+ # end
9
+ #
10
+ # context "performing request for collection" do
11
+ # setup do
12
+ # response = mock('response') do
13
+ # stubs(:body).returns(fixture_file('user_timeline.json'))
14
+ # stubs(:code).returns('200')
15
+ # end
16
+ #
17
+ # @client.expects(:get).returns(response)
18
+ # @object = @request.perform
19
+ # end
20
+ #
21
+ # should "return array of mashes" do
22
+ # @object.size.should == 20
23
+ # @object.each { |obj| obj.class.should be(Hashie::Mash) }
24
+ # @object.first.text.should == 'Colder out today than expected. Headed to the Beanery for some morning wakeup drink. Latte or coffee...hmmm...'
25
+ # end
26
+ # end
27
+ #
28
+ # context "performing a request for a single object" do
29
+ # setup do
30
+ # response = mock('response') do
31
+ # stubs(:body).returns(fixture_file('status.json'))
32
+ # stubs(:code).returns('200')
33
+ # end
34
+ #
35
+ # @client.expects(:get).returns(response)
36
+ # @object = @request.perform
37
+ # end
38
+ #
39
+ # should "return a single mash" do
40
+ # @object.class.should be(Hashie::Mash)
41
+ # @object.text.should == 'Rob Dyrdek is the funniest man alive. That is all.'
42
+ # end
43
+ # end
44
+ #
45
+ # context "with no query string" do
46
+ # should "not have any query string" do
47
+ # request = MambaNation::Request.new(@client, :get, '/users/4.json')
48
+ # request.uri.should == '/users/4.json'
49
+ # end
50
+ # end
51
+ #
52
+ # context "with blank query string" do
53
+ # should "not have any query string" do
54
+ # request = MambaNation::Request.new(@client, :get, '/users/4.json', :query => {})
55
+ # request.uri.should == '/users/4.json'
56
+ # end
57
+ # end
58
+ #
59
+ # should "have get shortcut to initialize and perform all in one" do
60
+ # MambaNation::Request.any_instance.expects(:perform).returns(nil)
61
+ # MambaNation::Request.get(@client, '/foo')
62
+ # end
63
+ #
64
+ # should "allow setting query string and headers" do
65
+ # response = mock('response') do
66
+ # stubs(:body).returns('')
67
+ # stubs(:code).returns('200')
68
+ # end
69
+ #
70
+ # @client.expects(:get).with('/1/statuses/friends_timeline.json?since_id=1234', {'Foo' => 'Bar'}).returns(response)
71
+ # MambaNation::Request.get(@client, '/1/statuses/friends_timeline.json?since_id=1234', :headers => {'Foo' => 'Bar'})
72
+ # end
73
+ # end
74
+ #
75
+ # context "new post request" do
76
+ # setup do
77
+ # @client = mock('mambanation client')
78
+ # @request = MambaNation::Request.new(@client, :post, '/1/statuses/update.json', {:body => {:status => 'Woohoo!'}})
79
+ # end
80
+ #
81
+ # should "allow setting body and headers" do
82
+ # response = mock('response') do
83
+ # stubs(:body).returns('')
84
+ # stubs(:code).returns('200')
85
+ # end
86
+ #
87
+ # @client.expects(:post).with('/1/statuses/update.json', {:status => 'Woohoo!'}, {'Foo' => 'Bar'}).returns(response)
88
+ # MambaNation::Request.post(@client, '/1/statuses/update.json', :body => {:status => 'Woohoo!'}, :headers => {'Foo' => 'Bar'})
89
+ # end
90
+ #
91
+ # context "performing request" do
92
+ # setup do
93
+ # response = mock('response') do
94
+ # stubs(:body).returns(fixture_file('status.json'))
95
+ # stubs(:code).returns('200')
96
+ # end
97
+ #
98
+ # @client.expects(:post).returns(response)
99
+ # @object = @request.perform
100
+ # end
101
+ #
102
+ # should "return a mash of the object" do
103
+ # @object.text.should == 'Rob Dyrdek is the funniest man alive. That is all.'
104
+ # end
105
+ # end
106
+ #
107
+ # should "have post shortcut to initialize and perform all in one" do
108
+ # MambaNation::Request.any_instance.expects(:perform).returns(nil)
109
+ # MambaNation::Request.post(@client, '/foo')
110
+ # end
111
+ # end
112
+ end
@@ -1,82 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  class MambaNationTest < Test::Unit::TestCase
4
- context "mambanation_base_api" do
5
-
6
- setup do
7
- @username = "website"
8
- @password = "mambanation"
9
- httpauth = MambaNation::HTTPAuth.new(@username, @password,:api_endpoint => "api.slot5.dev.mambanation.com"+'/'+"v2")
10
- @mambanation = MambaNation::Base.new(httpauth)
11
- end
12
-
13
- should "have user method for base authenticated calls to get a user's information" do
14
- stub_get("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/users/4.json",'user.json')
15
- user = @mambanation.user 4
16
- user.mamba_level.should == 1
17
- user.email.should == "tian.jiang01@gmail.com"
18
- end
19
-
20
- should "have facet method for base authenticated calls to get a facet's information" do
21
- stub_get("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/facets/1.json",'facet.json')
22
- facet = @mambanation.facet 1
23
- facet.user_id.should == 1
24
- end
25
-
26
- should "have user_facets method with given user for base authenticated calls to get a user's facet's information" do
27
- stub_get("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/users/5/facets.json",'facets.json')
28
- facets = @mambanation.user_facets(5)
29
- facets.facets.count.should == 1
30
- facets.facebook_id == nil
31
- end
32
-
33
-
34
- should "have user_friends method with given user for base authenticated calls to get a user's facet's information" do
35
- stub_get("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/users/5/friends.json",'friends.json')
36
- friends = @mambanation.user_friends(5)
37
- friends.count.should == 2
38
- end
39
-
40
-
41
- #media api for user in sdk is not rest
42
- #should "have user_media method with given user for base authenticated calls to get a user's media's information" do
43
- # stub_get("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/users/5/medias.json",'')
44
- # media
45
- #end
46
-
47
- #user_set_websession no more in sdk
48
- # should "be able to update websession for a user"
49
- # stub_post("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/facets/1.json",'')
50
- # end
51
-
52
- should "be able to create a user" do
53
- stub_post("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/users",'new_user_status.json')
54
- response = @mambanation.create_user("user"=>{"email"=>"foofoo@gmail.com","password"=>"foofoo","password_confirmation"=>"foofoo"})
55
- response.status.should == "ok"
56
- end
57
-
58
-
59
- should "be able to create a user with a facebook_id" do
60
- stub_post("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/users",'new_user_status.json')
61
- response = @mambanation.create_user("user"=>{"facebook_id"=>"1474761574"})
62
- response.status.should == "ok"
63
- end
64
-
65
- should "have user find by an existed facebook_id" do
66
- stub_get("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/users/find_by?facebook_id=1474761574",'user.json')
67
- user = @mambanation.user_by_facebook_id 1474761574
68
- user.mamba_level.should == 1
69
- user.email.should == "tian.jiang01@gmail.com"
70
- user.facebook_id.should == 1474761574
71
- end
72
-
73
-
74
- should "have not found message by an no existed facebook_id" do
75
- stub_get("http://#{@username}:#{@password}@api.slot5.dev.mambanation.com/v2/users/find_by?facebook_id=12345",'not_found_user.json')
76
- user = @mambanation.user_by_facebook_id 12345
77
- user.message.should == "I can't find this user !"
78
- end
79
-
80
4
 
81
- end
82
5
  end
data/test/test_helper.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "rubygems"
2
1
  require "test/unit"
3
2
  require "pathname"
4
3
  require "shoulda"
@@ -26,7 +25,7 @@ def fixture_file(filename)
26
25
  end
27
26
 
28
27
  def mambanation_url(url)
29
- url =~ /^http/ ? url : "http://api.mambanation.com:80#{url}"
28
+ url =~ /^http/ ? url : "http://username:password@api.mambanation.com/v2/#{url}"
30
29
  end
31
30
 
32
31
  def stub_get(url, filename, status=nil)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jeremy Van de Wyngaert
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-03 00:00:00 +02:00
17
+ date: 2010-08-10 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: oauth
21
+ name: hashie
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
@@ -26,13 +26,13 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 0
29
- - 3
30
- - 6
31
- version: 0.3.6
29
+ - 2
30
+ - 0
31
+ version: 0.2.0
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: hashie
35
+ name: httparty
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
@@ -40,13 +40,13 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 0
43
- - 2
43
+ - 5
44
44
  - 0
45
- version: 0.2.0
45
+ version: 0.5.0
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: httparty
49
+ name: yajl-ruby
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  requirements:
@@ -54,37 +54,37 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  segments:
56
56
  - 0
57
- - 5
58
- - 2
59
- version: 0.5.2
57
+ - 7
58
+ - 0
59
+ version: 0.7.0
60
60
  type: :runtime
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- name: json
63
+ name: shoulda
64
64
  prerelease: false
65
65
  requirement: &id004 !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  segments:
70
- - 1
71
- - 4
72
- - 3
73
- version: 1.4.3
74
- type: :runtime
70
+ - 2
71
+ - 10
72
+ - 0
73
+ version: 2.10.0
74
+ type: :development
75
75
  version_requirements: *id004
76
76
  - !ruby/object:Gem::Dependency
77
- name: shoulda
77
+ name: jnunemaker-matchy
78
78
  prerelease: false
79
79
  requirement: &id005 !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ~>
82
82
  - !ruby/object:Gem::Version
83
83
  segments:
84
- - 2
85
- - 10
86
- - 1
87
- version: 2.10.1
84
+ - 0
85
+ - 4
86
+ - 0
87
+ version: 0.4.0
88
88
  type: :development
89
89
  version_requirements: *id005
90
90
  - !ruby/object:Gem::Dependency
@@ -97,8 +97,8 @@ dependencies:
97
97
  segments:
98
98
  - 0
99
99
  - 9
100
- - 4
101
- version: 0.9.4
100
+ - 0
101
+ version: 0.9.0
102
102
  type: :development
103
103
  version_requirements: *id006
104
104
  - !ruby/object:Gem::Dependency
@@ -111,10 +111,24 @@ dependencies:
111
111
  segments:
112
112
  - 1
113
113
  - 2
114
- - 5
115
- version: 1.2.5
114
+ - 0
115
+ version: 1.2.0
116
116
  type: :development
117
117
  version_requirements: *id007
118
+ - !ruby/object:Gem::Dependency
119
+ name: redgreen
120
+ prerelease: false
121
+ requirement: &id008 !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 1
127
+ - 2
128
+ - 2
129
+ version: 1.2.2
130
+ type: :development
131
+ version_requirements: *id008
118
132
  description:
119
133
  email: jeremy.vandewyngaert@mimesis-republic.com
120
134
  executables: []
@@ -128,21 +142,35 @@ files:
128
142
  - LICENSE
129
143
  - README
130
144
  - Rakefile
131
- - VERSION
145
+ - VERSION.yml
132
146
  - lib/mambanation.rb
133
147
  - lib/mambanation/base.rb
134
148
  - lib/mambanation/httpauth.rb
135
149
  - lib/mambanation/oauth.rb
136
150
  - lib/mambanation/request.rb
151
+ - test/fixtures/actions.json
152
+ - test/fixtures/badges.json
153
+ - test/fixtures/chats.json
154
+ - test/fixtures/coms.json
137
155
  - test/fixtures/facet.json
138
156
  - test/fixtures/facets.json
139
157
  - test/fixtures/friends.json
158
+ - test/fixtures/last_login.json
140
159
  - test/fixtures/media.json
160
+ - test/fixtures/mission_families.json
161
+ - test/fixtures/mission_statuses.json
141
162
  - test/fixtures/new_user_status.json
142
163
  - test/fixtures/not_found_user.json
164
+ - test/fixtures/post.json
143
165
  - test/fixtures/posts.json
166
+ - test/fixtures/publish_post.json
167
+ - test/fixtures/roles.json
144
168
  - test/fixtures/user.json
169
+ - test/fixtures/user_error.json
170
+ - test/fixtures/user_posts.json
145
171
  - test/mambanation/base_test.rb
172
+ - test/mambanation/httpauth_test.rb
173
+ - test/mambanation/request_test.rb
146
174
  - test/mambanation_test.rb
147
175
  - test/test_helper.rb
148
176
  has_rdoc: true
@@ -175,5 +203,9 @@ rubygems_version: 1.3.6
175
203
  signing_key:
176
204
  specification_version: 3
177
205
  summary: wrapper for mambanation-api
178
- test_files: []
179
-
206
+ test_files:
207
+ - test/mambanation/base_test.rb
208
+ - test/mambanation/httpauth_test.rb
209
+ - test/mambanation/request_test.rb
210
+ - test/mambanation_test.rb
211
+ - test/test_helper.rb