mambanation 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/mambanation.rb +13 -7
- data/lib/mambanation/base.rb +7 -7
- data/lib/mambanation/request.rb +2 -3
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/mambanation.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "forwardable"
|
2
|
-
#require "oauth"
|
3
2
|
require "hashie"
|
4
3
|
require "httparty"
|
5
4
|
require "json"
|
@@ -7,7 +6,6 @@ require "json"
|
|
7
6
|
module MambaNation
|
8
7
|
include HTTParty
|
9
8
|
API_VERSION = "2".freeze
|
10
|
-
base_uri "api.mambanation.com/v#{API_VERSION}"
|
11
9
|
format :json
|
12
10
|
|
13
11
|
class MambaNationError < StandardError
|
@@ -27,9 +25,18 @@ module MambaNation
|
|
27
25
|
class InformMambaNation < StandardError; end
|
28
26
|
class NotFound < StandardError; end
|
29
27
|
|
28
|
+
def self.api_endpoint
|
29
|
+
@api_endpoint ||= "api.mambanation.com/v#{API_VERSION}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.api_endpoint=(value)
|
33
|
+
@api_endpoint = value
|
34
|
+
end
|
35
|
+
|
30
36
|
private
|
31
37
|
|
32
38
|
def self.perform_get(uri, options = {})
|
39
|
+
base_uri(self.api_endpoint)
|
33
40
|
make_friendly(get(uri, options))
|
34
41
|
end
|
35
42
|
|
@@ -65,10 +72,7 @@ module MambaNation
|
|
65
72
|
end
|
66
73
|
|
67
74
|
def self.parse(response)
|
68
|
-
|
69
|
-
JSON.parse(response.body)
|
70
|
-
rescue
|
71
|
-
response.body # Text body response
|
75
|
+
Yajl::Parser.parse(response.body)
|
72
76
|
end
|
73
77
|
|
74
78
|
def self.mash(obj)
|
@@ -94,6 +98,7 @@ end
|
|
94
98
|
|
95
99
|
module Hashie
|
96
100
|
class Mash
|
101
|
+
|
97
102
|
# Converts all of the keys to strings, optionally formatting key name
|
98
103
|
def rubyify_keys!
|
99
104
|
keys.each{|k|
|
@@ -105,6 +110,7 @@ module Hashie
|
|
105
110
|
}
|
106
111
|
self
|
107
112
|
end
|
113
|
+
|
108
114
|
end
|
109
115
|
end
|
110
116
|
|
@@ -112,5 +118,5 @@ directory = File.expand_path(File.dirname(__FILE__))
|
|
112
118
|
|
113
119
|
require File.join(directory, "mambanation", "base")
|
114
120
|
require File.join(directory, "mambanation", "httpauth")
|
115
|
-
require File.join(directory, "mambanation", "oauth")
|
121
|
+
#require File.join(directory, "mambanation", "oauth")
|
116
122
|
require File.join(directory, "mambanation", "request")
|
data/lib/mambanation/base.rb
CHANGED
@@ -140,8 +140,8 @@ module MambaNation
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def publish_post(id, stream_id)
|
143
|
-
perform_post("/posts/#{id.to_i}/publish"
|
144
|
-
|
143
|
+
perform_post("/posts/#{id.to_i}/publish", :body =>{ :post => { :stream_id => stream_id } })
|
144
|
+
end
|
145
145
|
|
146
146
|
#
|
147
147
|
# Roles
|
@@ -151,7 +151,7 @@ module MambaNation
|
|
151
151
|
end
|
152
152
|
|
153
153
|
protected
|
154
|
-
|
154
|
+
|
155
155
|
def self.mime_type(file)
|
156
156
|
case
|
157
157
|
when file =~ /\.jpg/ then 'image/jpg'
|
@@ -160,11 +160,11 @@ module MambaNation
|
|
160
160
|
else 'application/octet-stream'
|
161
161
|
end
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
def mime_type(f) self.class.mime_type(f) end
|
165
|
-
|
165
|
+
|
166
166
|
CRLF = "\r\n"
|
167
|
-
|
167
|
+
|
168
168
|
def self.build_multipart_bodies(parts)
|
169
169
|
boundary = Time.now.to_i.to_s(16)
|
170
170
|
body = ""
|
@@ -191,7 +191,7 @@ module MambaNation
|
|
191
191
|
|
192
192
|
private
|
193
193
|
|
194
|
-
def request_options
|
194
|
+
def request_options(opts={})
|
195
195
|
opts[:headers] ||= {}
|
196
196
|
opts[:headers].merge! "FB-Cookies" => fbs_cookies
|
197
197
|
opts
|
data/lib/mambanation/request.rb
CHANGED
@@ -29,17 +29,16 @@ module MambaNation
|
|
29
29
|
def uri
|
30
30
|
@uri ||= begin
|
31
31
|
uri = URI.parse(path)
|
32
|
-
|
32
|
+
|
33
33
|
if options[:query] && options[:query] != {}
|
34
34
|
uri.query = to_query(options[:query])
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
uri.to_s
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def perform
|
42
|
-
puts "\nuri: #{uri}\noptions[:body]: #{options[:body]}\noptions[:headers]: #{options[:headers]}"
|
43
42
|
MambaNation.make_friendly(send("perform_#{method}"))
|
44
43
|
end
|
45
44
|
|