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.
- data/Rakefile +30 -45
- data/VERSION.yml +4 -0
- data/lib/mambanation.rb +2 -2
- data/lib/mambanation/base.rb +125 -31
- data/lib/mambanation/httpauth.rb +10 -1
- data/lib/mambanation/oauth.rb +15 -9
- data/lib/mambanation/request.rb +4 -7
- data/test/fixtures/actions.json +12 -0
- data/test/fixtures/badges.json +12 -0
- data/test/fixtures/chats.json +25 -0
- data/test/fixtures/coms.json +18 -0
- data/test/fixtures/facets.json +15 -1
- data/test/fixtures/last_login.json +3 -0
- data/test/fixtures/mission_families.json +57 -0
- data/test/fixtures/mission_statuses.json +107 -0
- data/test/fixtures/post.json +36 -0
- data/test/fixtures/publish_post.json +43 -0
- data/test/fixtures/roles.json +5 -0
- data/test/fixtures/user_error.json +9 -0
- data/test/fixtures/user_posts.json +70 -0
- data/test/mambanation/base_test.rb +104 -16
- data/test/mambanation/httpauth_test.rb +86 -0
- data/test/mambanation/request_test.rb +112 -0
- data/test/mambanation_test.rb +0 -77
- data/test/test_helper.rb +1 -2
- metadata +64 -32
- data/VERSION +0 -1
data/Rakefile
CHANGED
@@ -1,50 +1,35 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
gem.add_development_dependency("fakeweb", "~> 1.2.5")
|
23
|
-
end
|
24
|
-
|
25
|
-
rescue LoadError
|
26
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
1
|
+
require "rake"
|
2
|
+
require "jeweler"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
Jeweler::Tasks.new do |gem|
|
6
|
+
gem.name = "mambanation"
|
7
|
+
gem.summary = %Q{wrapper for mambanation-api}
|
8
|
+
gem.email = "jeremy.vandewyngaert@mimesis-republic.com"
|
9
|
+
gem.homepage = "https://github.com/mimesis/mambanation-wrapper"
|
10
|
+
gem.authors = ["Jeremy Van de Wyngaert"]
|
11
|
+
gem.files = FileList["[A-Z]*", "{lib,test}/**/*"]
|
12
|
+
|
13
|
+
gem.add_dependency("hashie", "~> 0.2.0")
|
14
|
+
gem.add_dependency("httparty", "~> 0.5.0")
|
15
|
+
gem.add_dependency("yajl-ruby", "~> 0.7.0")
|
16
|
+
|
17
|
+
gem.add_development_dependency("shoulda", "~> 2.10.0")
|
18
|
+
gem.add_development_dependency("jnunemaker-matchy", "~> 0.4.0")
|
19
|
+
gem.add_development_dependency("mocha", "~> 0.9.0")
|
20
|
+
gem.add_development_dependency("fakeweb", "~> 1.2.0")
|
21
|
+
gem.add_development_dependency("redgreen", "~> 1.2.2")
|
27
22
|
end
|
28
23
|
|
29
|
-
|
30
|
-
t.libs << 'lib'
|
31
|
-
t.pattern = 'test/**/*_test.rb'
|
32
|
-
t.verbose = false
|
33
|
-
end
|
34
|
-
|
35
|
-
begin
|
36
|
-
require 'yard'
|
37
|
-
YARD::Rake::YardocTask.new(:yardoc)
|
38
|
-
rescue LoadError
|
39
|
-
task :yardoc do
|
40
|
-
abort "YARD is not available. In order to run yard, you must: sudo gem install yard"
|
41
|
-
end
|
42
|
-
end
|
24
|
+
Jeweler::GemcutterTasks.new
|
43
25
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
26
|
+
require "rake/testtask"
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << "test"
|
29
|
+
test.ruby_opts << "-rubygems"
|
30
|
+
test.pattern = "test/**/*_test.rb"
|
31
|
+
test.verbose = true
|
48
32
|
end
|
49
33
|
|
50
|
-
task :default
|
34
|
+
task :default => :test
|
35
|
+
task :test => :check_dependencies
|
data/VERSION.yml
ADDED
data/lib/mambanation.rb
CHANGED
@@ -28,8 +28,8 @@ module MambaNation
|
|
28
28
|
class NotFound < StandardError; end
|
29
29
|
|
30
30
|
# Options: user_id, facebook_id
|
31
|
-
def self.user(
|
32
|
-
perform_get("/users/show.json", :
|
31
|
+
def self.user(*user)
|
32
|
+
perform_get("/users/show.json", :body => { :user => user })
|
33
33
|
end
|
34
34
|
|
35
35
|
# Options: user_id, facebook_id
|
data/lib/mambanation/base.rb
CHANGED
@@ -1,54 +1,148 @@
|
|
1
1
|
module MambaNation
|
2
2
|
class Base
|
3
3
|
extend Forwardable
|
4
|
-
|
4
|
+
|
5
5
|
def_delegators :client, :get, :post, :put, :delete
|
6
|
-
|
6
|
+
|
7
7
|
attr_reader :client
|
8
|
-
|
8
|
+
|
9
9
|
def initialize(client)
|
10
10
|
@client = client
|
11
11
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
#
|
14
|
+
# Users
|
15
|
+
#
|
16
|
+
def create_user(user)
|
17
|
+
perform_post("/users", :body => { :user => user })
|
15
18
|
end
|
16
19
|
|
17
20
|
def user_by_facebook_id(facebook_id, query = {})
|
18
|
-
perform_get("/users/find_by?facebook_id=#{facebook_id}", :query => query)
|
21
|
+
perform_get("/users/find_by?facebook_id=#{facebook_id.to_i}", :query => query)
|
22
|
+
end
|
23
|
+
|
24
|
+
def user_by_email(email, query = {})
|
25
|
+
perform_get("/users/find_by?facebook_id=#{email}", :query => query)
|
19
26
|
end
|
20
27
|
|
21
28
|
# Options: user_id, facebook_id
|
22
29
|
def user(id, query = {})
|
23
|
-
perform_get("/users/#{id}.json", :query => query)
|
30
|
+
perform_get("/users/#{id.to_i}.json", :query => query)
|
24
31
|
end
|
32
|
+
alias_method :user_by_id, :user
|
25
33
|
|
26
34
|
def user_set_websession(id, credentials)
|
27
|
-
perform_post("/users/#{id}/update_websession", :body => { :user_credentials => credentials })
|
35
|
+
perform_post("/users/#{id.to_i}/update_websession", :body => { :user_credentials => credentials })
|
28
36
|
end
|
29
37
|
|
30
|
-
#
|
31
|
-
|
32
|
-
|
38
|
+
#
|
39
|
+
# User actions
|
40
|
+
#
|
41
|
+
def user_last_login(id)
|
42
|
+
perform_get("/users/#{id.to_i}/last_login.json")
|
33
43
|
end
|
34
44
|
|
35
|
-
|
36
|
-
|
37
|
-
|
45
|
+
def user_chats(id, query = {})
|
46
|
+
perform_get("/users/#{id.to_i}/chats.json", :query => query)
|
47
|
+
end
|
48
|
+
|
49
|
+
def user_coms(id, query = {})
|
50
|
+
perform_get("/users/#{id.to_i}/coms.json", :query => query)
|
51
|
+
end
|
52
|
+
|
53
|
+
def user_actions(id, query = {})
|
54
|
+
perform_get("/users/#{id.to_i}/actions.json", :query => query)
|
55
|
+
end
|
56
|
+
|
57
|
+
def activate_user(id)
|
58
|
+
perform_put("/users/#{id.to_i}/activate")
|
38
59
|
end
|
39
|
-
|
60
|
+
|
61
|
+
def anonymate_user(id)
|
62
|
+
perform_put("/users/#{id.to_i}/anonymate")
|
63
|
+
end
|
64
|
+
|
65
|
+
def suspend_user(id)
|
66
|
+
perform_put("/users/#{id.to_i}/suspend")
|
67
|
+
end
|
68
|
+
|
40
69
|
# Options: user_id, :limit
|
41
70
|
def user_media(id, query = {})
|
42
|
-
perform_get("/users/#{id}/media.json", :query => query)
|
71
|
+
perform_get("/users/#{id.to_i}/media.json", :query => query)
|
43
72
|
end
|
44
|
-
|
73
|
+
|
45
74
|
# Options: user_id, facebook_id
|
46
75
|
def user_friends(id, query = {})
|
47
|
-
perform_get("/users/#{id}/friends.json", :query => query)
|
76
|
+
perform_get("/users/#{id.to_i}/friends.json", :query => query)
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Facets
|
81
|
+
#
|
82
|
+
# Options: facet_id
|
83
|
+
def facet(id)
|
84
|
+
perform_get("/facets/#{id.to_i}.json")
|
85
|
+
end
|
86
|
+
|
87
|
+
# Options: user_id
|
88
|
+
def user_facets(id, query = {})
|
89
|
+
perform_get("/users/#{id.to_i}/facets.json", :query => query)
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# Badges
|
94
|
+
#
|
95
|
+
def badges
|
96
|
+
perform_get("/badges.json")
|
97
|
+
end
|
98
|
+
|
99
|
+
def user_badges(id, query = {})
|
100
|
+
perform_get("/users/#{id.to_i}/badges.json", :query => query)
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Mission Statuses
|
105
|
+
#
|
106
|
+
def mission_statuses(id, query = {})
|
107
|
+
perform_get("/users/#{id.to_i}/mission_statuses.json", :query => query)
|
108
|
+
end
|
109
|
+
|
110
|
+
def missions_family_statuses(id, query = {})
|
111
|
+
perform_get("/users/#{id.to_i}/missions_family_statuses.json", :query => query)
|
112
|
+
end
|
113
|
+
|
114
|
+
def mission_complete!(id, mission_id)
|
115
|
+
perform_put("/users/#{id.to_i}/mission_statuses/#{mission_id.to_i}/complete")
|
116
|
+
end
|
117
|
+
|
118
|
+
def mission_start!(id, mission_id)
|
119
|
+
perform_put("/users/#{id.to_i}/mission_statuses/#{mission_id.to_i}/start")
|
120
|
+
end
|
121
|
+
|
122
|
+
#
|
123
|
+
# Posts
|
124
|
+
#
|
125
|
+
def user_posts(id)
|
126
|
+
perform_get("/users/#{id.to_i}/posts.json")
|
127
|
+
end
|
128
|
+
|
129
|
+
def publish_post(post)
|
130
|
+
perform_post("/posts/publish", :body => { :post => post })
|
48
131
|
end
|
49
|
-
|
132
|
+
|
133
|
+
def post(id)
|
134
|
+
perform_get("/posts/#{id.to_i}.json")
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Roles
|
139
|
+
#
|
140
|
+
def user_roles(id)
|
141
|
+
perform_get("/users/#{id.to_i}/roles.json")
|
142
|
+
end
|
143
|
+
|
50
144
|
protected
|
51
|
-
|
145
|
+
|
52
146
|
def self.mime_type(file)
|
53
147
|
case
|
54
148
|
when file =~ /\.jpg/ then 'image/jpg'
|
@@ -57,11 +151,11 @@ module MambaNation
|
|
57
151
|
else 'application/octet-stream'
|
58
152
|
end
|
59
153
|
end
|
60
|
-
|
154
|
+
|
61
155
|
def mime_type(f) self.class.mime_type(f) end
|
62
|
-
|
156
|
+
|
63
157
|
CRLF = "\r\n"
|
64
|
-
|
158
|
+
|
65
159
|
def self.build_multipart_bodies(parts)
|
66
160
|
boundary = Time.now.to_i.to_s(16)
|
67
161
|
body = ""
|
@@ -83,26 +177,26 @@ module MambaNation
|
|
83
177
|
:headers => {"Content-Type" => "multipart/form-data; boundary=#{boundary}"}
|
84
178
|
}
|
85
179
|
end
|
86
|
-
|
180
|
+
|
87
181
|
def build_multipart_bodies(parts) self.class.build_multipart_bodies(parts) end
|
88
|
-
|
182
|
+
|
89
183
|
private
|
90
|
-
|
184
|
+
|
91
185
|
def perform_get(path, options={})
|
92
186
|
MambaNation::Request.get(self, path, options)
|
93
187
|
end
|
94
|
-
|
188
|
+
|
95
189
|
def perform_post(path, options={})
|
96
190
|
MambaNation::Request.post(self, path, options)
|
97
191
|
end
|
98
|
-
|
192
|
+
|
99
193
|
def perform_put(path, options={})
|
100
194
|
MambaNation::Request.put(self, path, options)
|
101
195
|
end
|
102
|
-
|
196
|
+
|
103
197
|
def perform_delete(path, options={})
|
104
198
|
MambaNation::Request.delete(self, path, options)
|
105
199
|
end
|
106
|
-
|
200
|
+
|
107
201
|
end
|
108
202
|
end
|
data/lib/mambanation/httpauth.rb
CHANGED
@@ -10,7 +10,16 @@ module MambaNation
|
|
10
10
|
@username, @password = username, password
|
11
11
|
@options = {:ssl => false}.merge(options)
|
12
12
|
options[:api_endpoint] ||= "api.mambanation.com"
|
13
|
-
|
13
|
+
|
14
|
+
if options[:api_version] == false
|
15
|
+
version_path = 2
|
16
|
+
else
|
17
|
+
options[:api_version] ||= API_VERSION
|
18
|
+
version_path = "#{options[:api_version]}"
|
19
|
+
end
|
20
|
+
|
21
|
+
self.class.base_uri "http#{'s' if options[:ssl]}://#{options[:api_endpoint]}/v#{version_path}"
|
22
|
+
self.class.default_timeout options[:timeout] if options[:timeout]
|
14
23
|
end
|
15
24
|
|
16
25
|
def get(uri, headers={})
|
data/lib/mambanation/oauth.rb
CHANGED
@@ -4,20 +4,26 @@ module MambaNation
|
|
4
4
|
|
5
5
|
def_delegators :access_token, :get, :post, :put, :delete
|
6
6
|
|
7
|
-
attr_reader :ctoken, :csecret, :consumer_options
|
7
|
+
attr_reader :ctoken, :csecret, :consumer_options, :api_endpoint, :signing_endpoint
|
8
8
|
|
9
9
|
# Options
|
10
|
-
# :sign_in => true to just sign in with
|
11
|
-
# (http://apiwiki.
|
10
|
+
# :sign_in => true to just sign in with twitter instead of doing oauth authorization
|
11
|
+
# (http://apiwiki.twitter.com/Sign-in-with-Twitter)
|
12
12
|
def initialize(ctoken, csecret, options={})
|
13
13
|
@ctoken, @csecret, @consumer_options = ctoken, csecret, {}
|
14
|
+
@api_endpoint = options[:api_endpoint] || 'http://api.twitter.com'
|
15
|
+
@signing_endpoint = options[:signing_endpoint] || 'http://api.twitter.com'
|
14
16
|
if options[:sign_in]
|
15
17
|
@consumer_options[:authorize_path] = '/oauth/authenticate'
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
def consumer
|
20
|
-
@consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site =>
|
22
|
+
@consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => api_endpoint}.merge(consumer_options))
|
23
|
+
end
|
24
|
+
|
25
|
+
def signing_consumer
|
26
|
+
@signing_consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => signing_endpoint, :request_endpoint => api_endpoint }.merge(consumer_options))
|
21
27
|
end
|
22
28
|
|
23
29
|
def set_callback_url(url)
|
@@ -27,21 +33,21 @@ module MambaNation
|
|
27
33
|
|
28
34
|
# Note: If using oauth with a web app, be sure to provide :oauth_callback.
|
29
35
|
# Options:
|
30
|
-
# :oauth_callback => String, url that
|
36
|
+
# :oauth_callback => String, url that twitter should redirect to
|
31
37
|
def request_token(options={})
|
32
|
-
@request_token ||=
|
38
|
+
@request_token ||= signing_consumer.get_request_token(options)
|
33
39
|
end
|
34
40
|
|
35
41
|
# For web apps use params[:oauth_verifier], for desktop apps,
|
36
|
-
# use the verifier is the pin that
|
42
|
+
# use the verifier is the pin that twitter gives users.
|
37
43
|
def authorize_from_request(rtoken, rsecret, verifier_or_pin)
|
38
|
-
request_token = ::OAuth::RequestToken.new(
|
44
|
+
request_token = ::OAuth::RequestToken.new(signing_consumer, rtoken, rsecret)
|
39
45
|
access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
|
40
46
|
@atoken, @asecret = access_token.token, access_token.secret
|
41
47
|
end
|
42
48
|
|
43
49
|
def access_token
|
44
|
-
@access_token ||= ::OAuth::AccessToken.new(
|
50
|
+
@access_token ||= ::OAuth::AccessToken.new(signing_consumer, @atoken, @asecret)
|
45
51
|
end
|
46
52
|
|
47
53
|
def authorize_from_access(atoken, asecret)
|
data/lib/mambanation/request.rb
CHANGED
@@ -3,15 +3,11 @@ module MambaNation
|
|
3
3
|
extend Forwardable
|
4
4
|
|
5
5
|
def self.get(client, path, options={})
|
6
|
-
|
7
|
-
# RAILS_DEFAULT_LOGGER.debug { "request: #{a.inspect}" }
|
8
|
-
a.perform
|
6
|
+
new(client, :get, path, options).perform
|
9
7
|
end
|
10
8
|
|
11
|
-
def self.post(client, path, options={})
|
12
|
-
|
13
|
-
# RAILS_DEFAULT_LOGGER.debug { "request: #{a.inspect}" }
|
14
|
-
a.perform
|
9
|
+
def self.post(client, path, options={})
|
10
|
+
new(client, :post, path, options).perform
|
15
11
|
end
|
16
12
|
|
17
13
|
def self.put(client, path, options={})
|
@@ -43,6 +39,7 @@ module MambaNation
|
|
43
39
|
end
|
44
40
|
|
45
41
|
def perform
|
42
|
+
puts "\nuri: #{uri}\noptions[:body]: #{options[:body]}\noptions[:headers]: #{options[:headers]}"
|
46
43
|
MambaNation.make_friendly(send("perform_#{method}"))
|
47
44
|
end
|
48
45
|
|