mambanation 0.1.5 → 0.1.6

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 CHANGED
@@ -1,13 +1,12 @@
1
1
  require "rake"
2
2
  require "jeweler"
3
- require "yaml"
4
3
 
5
4
  Jeweler::Tasks.new do |gem|
6
5
  gem.name = "mambanation"
7
6
  gem.summary = %Q{wrapper for mambanation-api}
8
7
  gem.email = ["jeremy.vandewyngaert@mimesis-republic.com", "sbellity@gmail.com"]
9
8
  gem.homepage = "https://github.com/mimesis/mambanation-wrapper"
10
- gem.authors = ["Jeremy Van de Wyngaert"]
9
+ gem.authors = ["Jeremy Van de Wyngaert", "Stéphane Bellity"]
11
10
  gem.files = FileList["[A-Z]*", "{lib,test}/**/*"]
12
11
 
13
12
  gem.add_dependency("hashie", "~> 0.2.0")
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 5
3
+ :patch: 6
4
4
  :build:
5
5
  :major: 0
@@ -37,7 +37,7 @@ module MambaNation
37
37
  alias_method :user_by_id, :user
38
38
 
39
39
  def user_set_websession(id, credentials)
40
- perform_post("/users/#{id.to_i}/update_websession", :body => { :user_credentials => credentials })
40
+ perform_post("/users/#{id.to_i}/update_websession", :query => { :user_credentials => credentials })
41
41
  end
42
42
 
43
43
  #
@@ -135,12 +135,12 @@ module MambaNation
135
135
  perform_post("/posts/create", :body => { :post => post })
136
136
  end
137
137
 
138
- def post(id)
138
+ def posts(id)
139
139
  perform_get("/posts/#{id.to_i}.json")
140
140
  end
141
141
 
142
142
  def publish_post(id, stream_id)
143
- perform_post("/posts/#{id.to_i}/publish", :body =>{ :post => { :stream_id => stream_id } })
143
+ perform_post("/posts/#{id.to_i}/publish.json", :body => { :post => { :stream_id => stream_id } })
144
144
  end
145
145
 
146
146
  #
@@ -193,7 +193,7 @@ module MambaNation
193
193
 
194
194
  def request_options(opts={})
195
195
  opts[:headers] ||= {}
196
- opts[:headers].merge! "FB-Cookies" => fbs_cookies
196
+ opts[:headers].merge! "FB-Cookies" => fbs_cookies if fbs_cookies
197
197
  opts
198
198
  end
199
199
 
@@ -7,18 +7,19 @@ module MambaNation
7
7
  attr_reader :username, :password, :options
8
8
 
9
9
  def initialize(username, password, options={})
10
+
10
11
  @username, @password = username, password
11
12
  @options = { :ssl => false, :timeout => 100 }.merge(options)
12
13
  options[:api_endpoint] ||= "api.mambanation.com"
13
14
 
14
15
  if options[:api_version] == false
15
- version_path = "v2"
16
+ version_path = "2"
16
17
  else
17
18
  options[:api_version] ||= API_VERSION
18
- version_path = "v#{options[:api_version]}"
19
+ version_path = "#{options[:api_version]}"
19
20
  end
20
21
 
21
- self.class.base_uri "http#{'s' if options[:ssl]}://#{options[:api_endpoint]}/#{version_path}"
22
+ self.class.base_uri "http#{'s' if options[:ssl]}://#{options[:api_endpoint]}/v#{version_path}"
22
23
  self.class.default_timeout options[:timeout] if options[:timeout]
23
24
  end
24
25
 
data/lib/mambanation.rb CHANGED
@@ -1,33 +1,32 @@
1
1
  require "forwardable"
2
2
  require "hashie"
3
3
  require "httparty"
4
- require "json"
5
4
  require "yajl"
6
5
 
7
6
  module MambaNation
8
7
  include HTTParty
9
8
  API_VERSION = "2".freeze
10
9
  format :json
11
-
10
+
12
11
  class MambaNationError < StandardError
13
12
  attr_reader :data
14
-
13
+
15
14
  def initialize(data)
16
15
  @data = data
17
16
  super
18
17
  end
19
18
  end
20
-
19
+
21
20
  class RateLimitExceeded < MambaNationError; end
22
21
  class Unauthorized < MambaNationError; end
23
22
  class General < MambaNationError; end
24
-
23
+
25
24
  class Unavailable < StandardError; end
26
25
  class InformMambaNation < StandardError; end
27
26
  class NotFound < StandardError; end
28
27
 
29
28
  def self.api_endpoint
30
- @api_endpoint ||= "api.mambanation.com/v#{API_VERSION}"
29
+ @api_endpoint ||= "api.mambanation.com"
31
30
  end
32
31
 
33
32
  def self.api_endpoint=(value)
@@ -35,12 +34,12 @@ module MambaNation
35
34
  end
36
35
 
37
36
  private
38
-
37
+
39
38
  def self.perform_get(uri, options = {})
40
39
  base_uri(self.api_endpoint)
41
40
  make_friendly(get(uri, options))
42
41
  end
43
-
42
+
44
43
  def self.make_friendly(response)
45
44
  raise_errors(response)
46
45
  data = parse(response)
@@ -51,7 +50,7 @@ module MambaNation
51
50
  mash(data)
52
51
  end
53
52
  end
54
-
53
+
55
54
  def self.raise_errors(response)
56
55
  case response.code.to_i
57
56
  when 400
@@ -119,5 +118,4 @@ directory = File.expand_path(File.dirname(__FILE__))
119
118
 
120
119
  require File.join(directory, "mambanation", "base")
121
120
  require File.join(directory, "mambanation", "httpauth")
122
- #require File.join(directory, "mambanation", "oauth")
123
121
  require File.join(directory, "mambanation", "request")
metadata CHANGED
@@ -5,16 +5,17 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jeremy Van de Wyngaert
13
+ - "St\xC3\xA9phane Bellity"
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-13 00:00:00 +02:00
18
+ date: 2010-08-15 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -148,7 +149,6 @@ files:
148
149
  - lib/mambanation.rb
149
150
  - lib/mambanation/base.rb
150
151
  - lib/mambanation/httpauth.rb
151
- - lib/mambanation/oauth.rb
152
152
  - lib/mambanation/request.rb
153
153
  - test/fixtures/actions.json
154
154
  - test/fixtures/badges.json
@@ -1,64 +0,0 @@
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, :api_endpoint, :signing_endpoint
8
-
9
- # Options
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
- def initialize(ctoken, csecret, options={})
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'
16
- if options[:sign_in]
17
- @consumer_options[:authorize_path] = '/oauth/authenticate'
18
- end
19
- end
20
-
21
- def consumer
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))
27
- end
28
-
29
- def set_callback_url(url)
30
- clear_request_token
31
- request_token(:oauth_callback => url)
32
- end
33
-
34
- # Note: If using oauth with a web app, be sure to provide :oauth_callback.
35
- # Options:
36
- # :oauth_callback => String, url that twitter should redirect to
37
- def request_token(options={})
38
- @request_token ||= signing_consumer.get_request_token(options)
39
- end
40
-
41
- # For web apps use params[:oauth_verifier], for desktop apps,
42
- # use the verifier is the pin that twitter gives users.
43
- def authorize_from_request(rtoken, rsecret, verifier_or_pin)
44
- request_token = ::OAuth::RequestToken.new(signing_consumer, rtoken, rsecret)
45
- access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
46
- @atoken, @asecret = access_token.token, access_token.secret
47
- end
48
-
49
- def access_token
50
- @access_token ||= ::OAuth::AccessToken.new(signing_consumer, @atoken, @asecret)
51
- end
52
-
53
- def authorize_from_access(atoken, asecret)
54
- @atoken, @asecret = atoken, asecret
55
- end
56
-
57
- private
58
-
59
- def clear_request_token
60
- @request_token = nil
61
- end
62
-
63
- end
64
- end