mambanation 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/LICENSE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2010 Mimesis Republic
data/README ADDED
@@ -0,0 +1,9 @@
1
+ mambanation
2
+ ===============
3
+
4
+ This project is a wrapper over Mamba Nation API.
5
+
6
+ COPYRIGHT
7
+ =========
8
+
9
+ Copyright (c) 2010 Mimesis Republic. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rake'
2
+ require 'jeweler'
3
+ require 'rake/testtask'
4
+ require 'rcov/rcovtask'
5
+
6
+ begin
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "mambanation-wrapper"
9
+ gem.summary = "wrapper for mambanation-api"
10
+ gem.email = "jeremy.vandewyngaert@mimesis-republic.com"
11
+ gem.homepage = "http://mercurial-paris.mimesis-republic.net/hg/mambanation"
12
+ gem.authors = ["Jeremy Van de Wyngaert"]
13
+ gem.files = FileList["[A-Z]*", "{lib,test}/**/*"]
14
+
15
+ gem.add_dependency("oauth", "~> 0.3.6")
16
+ gem.add_dependency("hashie", "~> 0.2.0")
17
+ gem.add_dependency("httparty", "~> 0.5.2")
18
+ gem.add_dependency("json", "~> 1.4.3")
19
+
20
+ gem.add_development_dependency("shoulda", "~> 2.10.1")
21
+ gem.add_development_dependency("mocha", "~> 0.9.4")
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"
27
+ end
28
+
29
+ Rake::TestTask.new do |t|
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
43
+
44
+ Rcov::RcovTask.new do |t|
45
+ t.libs << "test"
46
+ t.test_files = FileList['test/*_test.rb']
47
+ t.verbose = true
48
+ end
49
+
50
+ task :default => :rcov
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,108 @@
1
+ module MambaNation
2
+ class Base
3
+ extend Forwardable
4
+
5
+ def_delegators :client, :get, :post, :put, :delete
6
+
7
+ attr_reader :client
8
+
9
+ def initialize(client)
10
+ @client = client
11
+ end
12
+
13
+ def create_user(query)
14
+ perform_post("/users", :body => query)
15
+ end
16
+
17
+ def user_by_facebook_id(facebook_id, query = {})
18
+ perform_get("/users/find_by?facebook_id=#{facebook_id}", :query => query)
19
+ end
20
+
21
+ # Options: user_id, facebook_id
22
+ def user(id, query = {})
23
+ perform_get("/users/#{id}.json", :query => query)
24
+ end
25
+
26
+ def user_set_websession(id, credentials)
27
+ perform_post("/users/#{id}/update_websession", :body => { :user_credentials => credentials })
28
+ end
29
+
30
+ # Options: facet_id
31
+ def facet(id)
32
+ perform_get("/facets/#{id}.json")
33
+ end
34
+
35
+ # Options: user_id
36
+ def user_facets(id, query = {})
37
+ perform_get("/users/#{id}/facets.json", :query => query)
38
+ end
39
+
40
+ # Options: user_id, :limit
41
+ def user_media(id, query = {})
42
+ perform_get("/users/#{id}/media.json", :query => query)
43
+ end
44
+
45
+ # Options: user_id, facebook_id
46
+ def user_friends(id, query = {})
47
+ perform_get("/users/#{id}/friends.json", :query => query)
48
+ end
49
+
50
+ protected
51
+
52
+ def self.mime_type(file)
53
+ case
54
+ when file =~ /\.jpg/ then 'image/jpg'
55
+ when file =~ /\.gif$/ then 'image/gif'
56
+ when file =~ /\.png$/ then 'image/png'
57
+ else 'application/octet-stream'
58
+ end
59
+ end
60
+
61
+ def mime_type(f) self.class.mime_type(f) end
62
+
63
+ CRLF = "\r\n"
64
+
65
+ def self.build_multipart_bodies(parts)
66
+ boundary = Time.now.to_i.to_s(16)
67
+ body = ""
68
+ parts.each do |key, value|
69
+ esc_key = CGI.escape(key.to_s)
70
+ body << "--#{boundary}#{CRLF}"
71
+ if value.respond_to?(:read)
72
+ body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{CRLF}"
73
+ body << "Content-Type: #{mime_type(value.path)}#{CRLF*2}"
74
+ body << value.read
75
+ else
76
+ body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}"
77
+ end
78
+ body << CRLF
79
+ end
80
+ body << "--#{boundary}--#{CRLF*2}"
81
+ {
82
+ :body => body,
83
+ :headers => {"Content-Type" => "multipart/form-data; boundary=#{boundary}"}
84
+ }
85
+ end
86
+
87
+ def build_multipart_bodies(parts) self.class.build_multipart_bodies(parts) end
88
+
89
+ private
90
+
91
+ def perform_get(path, options={})
92
+ MambaNation::Request.get(self, path, options)
93
+ end
94
+
95
+ def perform_post(path, options={})
96
+ MambaNation::Request.post(self, path, options)
97
+ end
98
+
99
+ def perform_put(path, options={})
100
+ MambaNation::Request.put(self, path, options)
101
+ end
102
+
103
+ def perform_delete(path, options={})
104
+ MambaNation::Request.delete(self, path, options)
105
+ end
106
+
107
+ end
108
+ end
@@ -0,0 +1,39 @@
1
+ module MambaNation
2
+ class HTTPAuth
3
+ include HTTParty
4
+
5
+ format :plain
6
+
7
+ attr_reader :username, :password, :options
8
+
9
+ def initialize(username, password, options={})
10
+ @username, @password = username, password
11
+ @options = {:ssl => false}.merge(options)
12
+ options[:api_endpoint] ||= "api.mambanation.com"
13
+ self.class.base_uri "http#{'s' if options[:ssl]}://#{options[:api_endpoint]}"
14
+ end
15
+
16
+ def get(uri, headers={})
17
+ self.class.get(uri, :headers => headers, :basic_auth => basic_auth)
18
+ end
19
+
20
+ def post(uri, body={}, headers={})
21
+ self.class.post(uri, :body => body, :headers => headers, :basic_auth => basic_auth)
22
+ end
23
+
24
+ def put(uri, body={}, headers={})
25
+ self.class.put(uri, :body => body, :headers => headers, :basic_auth => basic_auth)
26
+ end
27
+
28
+ def delete(uri, body={}, headers={})
29
+ self.class.delete(uri, :body => body, :headers => headers, :basic_auth => basic_auth)
30
+ end
31
+
32
+ private
33
+
34
+ def basic_auth
35
+ @basic_auth ||= {:username => @username, :password => @password}
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,58 @@
1
+ module MambaNation
2
+ class OAuth
3
+ extend Forwardable
4
+
5
+ def_delegators :access_token, :get, :post, :put, :delete
6
+
7
+ attr_reader :ctoken, :csecret, :consumer_options
8
+
9
+ # Options
10
+ # :sign_in => true to just sign in with mambanation instead of doing oauth authorization
11
+ # (http://apiwiki.mambanation.com/Sign-in-with-MambaNation)
12
+ def initialize(ctoken, csecret, options={})
13
+ @ctoken, @csecret, @consumer_options = ctoken, csecret, {}
14
+ if options[:sign_in]
15
+ @consumer_options[:authorize_path] = '/oauth/authenticate'
16
+ end
17
+ end
18
+
19
+ def consumer
20
+ @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://api.mambanation.com'}.merge(consumer_options))
21
+ end
22
+
23
+ def set_callback_url(url)
24
+ clear_request_token
25
+ request_token(:oauth_callback => url)
26
+ end
27
+
28
+ # Note: If using oauth with a web app, be sure to provide :oauth_callback.
29
+ # Options:
30
+ # :oauth_callback => String, url that mambanation should redirect to
31
+ def request_token(options={})
32
+ @request_token ||= consumer.get_request_token(options)
33
+ end
34
+
35
+ # For web apps use params[:oauth_verifier], for desktop apps,
36
+ # use the verifier is the pin that mambanation gives users.
37
+ def authorize_from_request(rtoken, rsecret, verifier_or_pin)
38
+ request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
39
+ access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
40
+ @atoken, @asecret = access_token.token, access_token.secret
41
+ end
42
+
43
+ def access_token
44
+ @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
45
+ end
46
+
47
+ def authorize_from_access(atoken, asecret)
48
+ @atoken, @asecret = atoken, asecret
49
+ end
50
+
51
+ private
52
+
53
+ def clear_request_token
54
+ @request_token = nil
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,75 @@
1
+ module MambaNation
2
+ class Request
3
+ extend Forwardable
4
+
5
+ def self.get(client, path, options={})
6
+ a = new(client, :get, path, options)
7
+ # RAILS_DEFAULT_LOGGER.debug { "request: #{a.inspect}" }
8
+ a.perform
9
+ end
10
+
11
+ def self.post(client, path, options={})
12
+ a = new(client, :post, path, options)
13
+ # RAILS_DEFAULT_LOGGER.debug { "request: #{a.inspect}" }
14
+ a.perform
15
+ end
16
+
17
+ def self.put(client, path, options={})
18
+ new(client, :put, path, options).perform
19
+ end
20
+
21
+ def self.delete(client, path, options={})
22
+ new(client, :delete, path, options).perform
23
+ end
24
+
25
+ attr_reader :client, :method, :path, :options
26
+
27
+ def_delegators :client, :get, :post, :put, :delete
28
+
29
+ def initialize(client, method, path, options={})
30
+ @client, @method, @path, @options = client, method, path, options
31
+ end
32
+
33
+ def uri
34
+ @uri ||= begin
35
+ uri = URI.parse(path)
36
+
37
+ if options[:query] && options[:query] != {}
38
+ uri.query = to_query(options[:query])
39
+ end
40
+
41
+ uri.to_s
42
+ end
43
+ end
44
+
45
+ def perform
46
+ MambaNation.make_friendly(send("perform_#{method}"))
47
+ end
48
+
49
+ private
50
+
51
+ def perform_get
52
+ get(uri, options[:headers])
53
+ end
54
+
55
+ def perform_post
56
+ post(uri, options[:body], options[:headers])
57
+ end
58
+
59
+ def perform_put
60
+ put(uri, options[:body], options[:headers])
61
+ end
62
+
63
+ def perform_delete
64
+ delete(uri, options[:headers])
65
+ end
66
+
67
+ def to_query(options)
68
+ options.inject([]) do |collection, opt|
69
+ collection << "#{opt[0]}=#{opt[1]}"
70
+ collection
71
+ end * '&'
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,136 @@
1
+ require "forwardable"
2
+ #require "oauth"
3
+ require "hashie"
4
+ require "httparty"
5
+ require "json"
6
+
7
+ module MambaNation
8
+ include HTTParty
9
+ API_VERSION = "2".freeze
10
+ base_uri "api.mambanation.com/v#{API_VERSION}"
11
+ format :json
12
+
13
+ class MambaNationError < StandardError
14
+ attr_reader :data
15
+
16
+ def initialize(data)
17
+ @data = data
18
+ super
19
+ end
20
+ end
21
+
22
+ class RateLimitExceeded < MambaNationError; end
23
+ class Unauthorized < MambaNationError; end
24
+ class General < MambaNationError; end
25
+
26
+ class Unavailable < StandardError; end
27
+ class InformMambaNation < StandardError; end
28
+ class NotFound < StandardError; end
29
+
30
+ # Options: user_id, facebook_id
31
+ def self.user(query = {})
32
+ perform_get("/users/show.json", :query => query)
33
+ end
34
+
35
+ # Options: user_id, facebook_id
36
+ def self.user_facets(query = {})
37
+ perform_get("/users/facets.json", :query => query)
38
+ end
39
+
40
+ # Options: user_id, :limit
41
+ def self.user_media(query = {})
42
+ perform_get("/users/media.json", :query => query)
43
+ end
44
+
45
+ # Options: user_id, facebook_id
46
+ def self.user_friends(query = {})
47
+ perform_get("/users/friends.json", :query => query)
48
+ end
49
+
50
+ private
51
+
52
+ def self.perform_get(uri, options = {})
53
+ make_friendly(get(uri, options))
54
+ end
55
+
56
+ def self.make_friendly(response)
57
+ raise_errors(response)
58
+ data = parse(response)
59
+ # Don't mash arrays of integers
60
+ if data && data.is_a?(Array) && data.first.is_a?(Integer)
61
+ data
62
+ else
63
+ mash(data)
64
+ end
65
+ end
66
+
67
+ def self.raise_errors(response)
68
+ case response.code.to_i
69
+ when 400
70
+ data = parse(response)
71
+ raise RateLimitExceeded.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}"
72
+ when 401
73
+ data = parse(response)
74
+ raise Unauthorized.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}"
75
+ when 403
76
+ data = parse(response)
77
+ raise General.new(data), "(#{response.code}): #{response.message} - #{data['error'] if data}"
78
+ when 404
79
+ raise NotFound, "(#{response.code}): #{response.message}"
80
+ when 500
81
+ raise InformMambaNation, "MambaNation had an internal error. Please let them know in the group. (#{response.code}): #{response.message}"
82
+ when 502..503
83
+ raise Unavailable, "(#{response.code}): #{response.message}"
84
+ end
85
+ end
86
+
87
+ def self.parse(response)
88
+ return '' if response.body == ''
89
+ JSON.parse(response.body)
90
+ rescue
91
+ response.body # Text body response
92
+ end
93
+
94
+ def self.mash(obj)
95
+ if obj.is_a?(Array)
96
+ obj.map{|item| make_mash_with_consistent_hash(item)}
97
+ elsif obj.is_a?(Hash)
98
+ make_mash_with_consistent_hash(obj)
99
+ else
100
+ obj
101
+ end
102
+ end
103
+
104
+ # Lame workaround for the fact that mash doesn't hash correctly
105
+ def self.make_mash_with_consistent_hash(obj)
106
+ m = Hashie::Mash.new(obj)
107
+ def m.hash
108
+ inspect.hash
109
+ end
110
+ return m
111
+ end
112
+
113
+ end
114
+
115
+ module Hashie
116
+ class Mash
117
+ # Converts all of the keys to strings, optionally formatting key name
118
+ def rubyify_keys!
119
+ keys.each{|k|
120
+ v = delete(k)
121
+ new_key = k.to_s.underscore
122
+ self[new_key] = v
123
+ v.rubyify_keys! if v.is_a?(Hash)
124
+ v.each{|p| p.rubyify_keys! if p.is_a?(Hash)} if v.is_a?(Array)
125
+ }
126
+ self
127
+ end
128
+ end
129
+ end
130
+
131
+ directory = File.expand_path(File.dirname(__FILE__))
132
+
133
+ require File.join(directory, "mambanation", "base")
134
+ require File.join(directory, "mambanation", "httpauth")
135
+ require File.join(directory, "mambanation", "oauth")
136
+ require File.join(directory, "mambanation", "request")
@@ -0,0 +1 @@
1
+ {"status":"active","type":null,"updated_at":1276597897,"equipement":null,"deleted_at":null,"user_id":1,"created_at":1276597897,"fame":"-","gender":null,"name":"b1276597897770707","fingerprint":null,"id":1}
@@ -0,0 +1 @@
1
+ {"facebook_id":null,"facets":[{"status":"active","type":null,"updated_at":1276761896,"equipement":null,"deleted_at":null,"user_id":5,"created_at":1276761896,"fame":"-","gender":null,"name":"b1276761896400393","fingerprint":null,"id":5}],"id":null}
@@ -0,0 +1,20 @@
1
+ [{
2
+ "avatar": {
3
+ "name": "b0383835001265278485",
4
+ "updated_at": 1265365397,
5
+ "gender": "F",
6
+ "type": "Black Female",
7
+ "fingerprint": "f5ad37e2229a7e898e8de3828fff472"
8
+ },
9
+ "facebook_id": "100000195107250"
10
+ },
11
+ {
12
+ "avatar": {
13
+ "name": "b1266312037913899",
14
+ "updated_at": 1266401611,
15
+ "gender": "M",
16
+ "type": "WhiteGuy",
17
+ "fingerprint": "b8959f9d5dfa617d328cec2bfb591776"
18
+ },
19
+ "facebook_id": "100000606276736"
20
+ }]
@@ -0,0 +1,18 @@
1
+ [{
2
+ "animation_id": "NEWYEAR",
3
+ "generated_at": 1265988898,
4
+ "type": "video",
5
+ "avatar_fingerprint": "a58273399279a545db50c9d75dddfec"
6
+ },
7
+ {
8
+ "animation_id": "CHRISTMAS",
9
+ "generated_at": 1265988900,
10
+ "type": "video",
11
+ "avatar_fingerprint": "a58273399279a545db50c9d75dddfec"
12
+ },
13
+ {
14
+ "animation_id": "LOL",
15
+ "generated_at": 1265988902,
16
+ "type": "video",
17
+ "avatar_fingerprint": "a58273399279a545db50c9d75dddfec"
18
+ }]
@@ -0,0 +1,3 @@
1
+ {
2
+ "status": "ok"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "message" : "I can't find this user !"
3
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "created_at": 1267107614,
3
+ "published_streams": {
4
+ "100000436786256": "100000436786256_105254089499150"
5
+ },
6
+ "updated_at": 1267107616,
7
+ "action_links": {
8
+ "0": {
9
+ "href": "http://apps.facebook.com/mambatemplate?post_id={{post_id}}",
10
+ "text": "Reply !"
11
+ }
12
+ },
13
+ "attachment": {
14
+ "href": "http://api.sandbox.mambanation.com:3001/v1/",
15
+ "name": "NEWYEAR",
16
+ "media": [{
17
+ "expanded_width": "320",
18
+ "swfsrc": "http://api.sandbox.mambanation.com/flv_player.swf?flv=http://d387vg9sga25dr.cloudfront.net/video/1da41a11cf6570642ba9d7c91f2c48_NEWYEAR.flv",
19
+ "imgsrc": "http://d387vg9sga25dr.cloudfront.net/preview/1da41a11cf6570642ba9d7c91f2c48_NEWYEAR.png",
20
+ "type": "flash",
21
+ "expanded_height": "260"
22
+ }]
23
+ },
24
+ "_id": "4b86871ed45037109900001c",
25
+ "fb_application_id": "293415521400",
26
+ "uid": "100000436786256",
27
+ "other": {
28
+ "example": "1234"
29
+ },
30
+ "message": "hihihi",
31
+ "target_ids": ["100000436786256"]
32
+ }
@@ -0,0 +1 @@
1
+ {"mamba_level":1,"facebook_id":1474761574,"points_to_next_level":150,"websession_id":4,"applications":{},"avatar":{"name":"b1276619510847471","updated_at":1276619510,"gender":null,"id":4,"type":null,"fingerprint":null},"gender":null,"id":4,"media":[],"percent_of_current_level":0,"blings":0,"last_name":null,"posts":{"count_received":0,"count_sent":0},"mamba_points":0,"status":"active","vibes":"-","email":"tian.jiang01@gmail.com","first_name":null}
@@ -0,0 +1,22 @@
1
+ require '../test_helper'
2
+ require '../../lib/mambanation/base.rb'
3
+
4
+
5
+ class BaseTest < Test::Unit::TestCase
6
+ context "base" do
7
+ setup do
8
+ oauth = Mambanation::OAuth.new("token", "secret")
9
+ @access_token = Mambanation::OAuth::AccessToken.new(oauth.consumer, "atoken", "asecret")
10
+ oauth.stubs(:access_token).returns(@access_token)
11
+ @mambanation = Mambanation::Base.new(oauth)
12
+ end
13
+
14
+ context "initialize" do
15
+ should "require a client" do
16
+ @mambanation.client.should respond_to(:get)
17
+ @mambanation.client.should respond_to(:post)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,82 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
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
+
81
+ end
82
+ end
@@ -0,0 +1,48 @@
1
+ require "rubygems"
2
+ require "test/unit"
3
+ require "pathname"
4
+ require "shoulda"
5
+ require "matchy"
6
+ require "mocha"
7
+ require "fakeweb"
8
+ require "redgreen"
9
+
10
+ FakeWeb.allow_net_connect = false
11
+
12
+ dir = (Pathname(__FILE__).dirname + "../lib").expand_path
13
+ require dir + "mambanation"
14
+
15
+ class Test::Unit::TestCase
16
+ end
17
+
18
+ def sample_image(filename)
19
+ File.expand_path(File.dirname(__FILE__) + "/fixtures/" + filename)
20
+ end
21
+
22
+ def fixture_file(filename)
23
+ return "" if filename == ""
24
+ file_path = File.expand_path(File.dirname(__FILE__) + "/fixtures/" + filename)
25
+ File.read(file_path)
26
+ end
27
+
28
+ def mambanation_url(url)
29
+ url =~ /^http/ ? url : "http://api.mambanation.com:80#{url}"
30
+ end
31
+
32
+ def stub_get(url, filename, status=nil)
33
+ options = {:body => fixture_file(filename)}
34
+ options.merge!({:status => status}) unless status.nil?
35
+ FakeWeb.register_uri(:get, mambanation_url(url), options)
36
+ end
37
+
38
+ def stub_post(url, filename)
39
+ FakeWeb.register_uri(:post, mambanation_url(url), :body => fixture_file(filename))
40
+ end
41
+
42
+ def stub_put(url, filename)
43
+ FakeWeb.register_uri(:put, mambanation_url(url), :body => fixture_file(filename))
44
+ end
45
+
46
+ def stub_delete(url, filename)
47
+ FakeWeb.register_uri(:delete, mambanation_url(url), :body => fixture_file(filename))
48
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mambanation
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jeremy Van de Wyngaert
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-03 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: oauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 3
30
+ - 6
31
+ version: 0.3.6
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: hashie
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 2
44
+ - 0
45
+ version: 0.2.0
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: httparty
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 5
58
+ - 2
59
+ version: 0.5.2
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: json
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 2
72
+ - 3
73
+ version: 1.2.3
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: shoulda
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 2
85
+ - 10
86
+ - 1
87
+ version: 2.10.1
88
+ type: :development
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: mocha
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ - 9
100
+ - 4
101
+ version: 0.9.4
102
+ type: :development
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: fakeweb
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 1
113
+ - 2
114
+ - 5
115
+ version: 1.2.5
116
+ type: :development
117
+ version_requirements: *id007
118
+ description:
119
+ email: jeremy.vandewyngaert@mimesis-republic.com
120
+ executables: []
121
+
122
+ extensions: []
123
+
124
+ extra_rdoc_files:
125
+ - LICENSE
126
+ - README
127
+ files:
128
+ - LICENSE
129
+ - README
130
+ - Rakefile
131
+ - VERSION
132
+ - lib/mambanation.rb
133
+ - lib/mambanation/base.rb
134
+ - lib/mambanation/httpauth.rb
135
+ - lib/mambanation/oauth.rb
136
+ - lib/mambanation/request.rb
137
+ - test/fixtures/facet.json
138
+ - test/fixtures/facets.json
139
+ - test/fixtures/friends.json
140
+ - test/fixtures/media.json
141
+ - test/fixtures/new_user_status.json
142
+ - test/fixtures/not_found_user.json
143
+ - test/fixtures/posts.json
144
+ - test/fixtures/user.json
145
+ - test/mambanation/base_test.rb
146
+ - test/mambanation_test.rb
147
+ - test/test_helper.rb
148
+ has_rdoc: true
149
+ homepage: https://github.com/mimesis/mambanation-wrapper
150
+ licenses: []
151
+
152
+ post_install_message:
153
+ rdoc_options:
154
+ - --charset=UTF-8
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ segments:
169
+ - 0
170
+ version: "0"
171
+ requirements: []
172
+
173
+ rubyforge_project:
174
+ rubygems_version: 1.3.6
175
+ signing_key:
176
+ specification_version: 3
177
+ summary: wrapper for mambanation-api
178
+ test_files: []
179
+