Module: InklingApi::ApiMethods
- Included in:
- InklingApi
- Defined in:
- lib/inkling_api.rb
Instance Method Summary collapse
- #answer(stock_id) ⇒ Object
- #cash_out(stock_id, price = 0) ⇒ Object
- #comments(market_id) ⇒ Object
- #create_answer(answer, symbol, market_id) ⇒ Object
- #create_membership(login, email, password, first_name, last_name) ⇒ Object
- #create_refund(stock_id) ⇒ Object
- #create_trade(stock_id, membership_id, quantity) ⇒ Object
- #delete(path, params = nil) ⇒ Object
- #delete_answer(stock_id) ⇒ Object
- #delete_market(market_id) ⇒ Object
- #delete_membership(membership_id) ⇒ Object
- #get(path, params = nil) ⇒ Object
- #get_token_for(membership_id) ⇒ Object
- #market(market_id, *args) ⇒ Object
- #markets(*args) ⇒ Object
-
#me ⇒ Object
Get’s membership of current logged in user.
- #membership(member_id, *args) ⇒ Object
- #memberships(*args) ⇒ Object
- #new_market(question, class_type, ends_at, tag_list) ⇒ Object
- #positions(membership_id) ⇒ Object
- #post(path, payload, params = nil) ⇒ Object
- #prices(*args) ⇒ Object
- #publish(path, params = nil) ⇒ Object
- #publish_market(market_id) ⇒ Object
- #put(path, payload, params = nil) ⇒ Object
- #quote(stock_id, membership_id, quantity) ⇒ Object
- #refund(path, params = nil) ⇒ Object
- #trades ⇒ Object
- #update_answer(stock_id, answer, symbol, starting_price) ⇒ Object
- #update_balance(balance_value, membership_id) ⇒ Object
- #update_market(market_id, question) ⇒ Object
- #update_membership(first_name, last_name, membership_id) ⇒ Object
Instance Method Details
#answer(stock_id) ⇒ Object
224 225 226 |
# File 'lib/inkling_api.rb', line 224 def answer(stock_id) get("stocks/#{stock_id}.xml") end |
#cash_out(stock_id, price = 0) ⇒ Object
240 241 242 243 |
# File 'lib/inkling_api.rb', line 240 def cash_out(stock_id, price = 0) cash_out_data = { :'price' => price } post("stocks/#{stock_id}/resolutions.xml", cash_out_data.to_xml(:root => "resolution"), :content_type => 'application/xml') end |
#comments(market_id) ⇒ Object
267 268 269 270 271 272 273 274 275 |
# File 'lib/inkling_api.rb', line 267 def comments(market_id) trades = get("/markets/#{market_id}/trades.xml")["trades"] ugly_comments = trades.select{ |t| !t["reason"].nil? } pretty_comments = Array.new ugly_comments = [] if ugly_comments.nil? ugly_comments.each do |c| pretty_comments << { c["membership"]["id"] => c["reason"] } end end |
#create_answer(answer, symbol, market_id) ⇒ Object
217 218 219 220 221 222 |
# File 'lib/inkling_api.rb', line 217 def create_answer(answer, symbol, market_id) answer_data = { :'name' => answer, :'symbol' => symbol } post("markets/#{market_id}/stocks.xml", answer_data.to_xml(:root => "stock"), :content_type => 'application/xml') end |
#create_membership(login, email, password, first_name, last_name) ⇒ Object
181 182 183 184 185 186 187 188 189 |
# File 'lib/inkling_api.rb', line 181 def create_membership(login, email, password, first_name, last_name) membership_data = { :'login' => login, :'password' => password, :'email' => email, :'first-name' => first_name, :'last-name' => last_name } post("memberships.xml", membership_data.to_xml(:root => "membership"), :content_type => 'application/xml') end |
#create_refund(stock_id) ⇒ Object
245 246 247 |
# File 'lib/inkling_api.rb', line 245 def create_refund(stock_id) refund("stocks/#{stock_id}/refunds.xml") end |
#create_trade(stock_id, membership_id, quantity) ⇒ Object
253 254 255 256 257 258 |
# File 'lib/inkling_api.rb', line 253 def create_trade(stock_id, membership_id, quantity) trade_data = { :'quantity' => quantity, :'membership_id' => membership_id } post("stocks/#{stock_id}/trades.xml", trade_data.to_xml(:root => "trade"), :content_type => 'application/xml') end |
#delete(path, params = nil) ⇒ Object
121 122 123 124 125 |
# File 'lib/inkling_api.rb', line 121 def delete(path, params = nil) raw = params && params.delete(:raw) response = super raw ? response.env[:raw_body] : response.body end |
#delete_answer(stock_id) ⇒ Object
236 237 238 |
# File 'lib/inkling_api.rb', line 236 def delete_answer(stock_id) delete("stocks/#{stock_id}.xml") end |
#delete_market(market_id) ⇒ Object
161 162 163 |
# File 'lib/inkling_api.rb', line 161 def delete_market(market_id) delete("markets/#{market_id}.xml", :content_type => 'application/xml') end |
#delete_membership(membership_id) ⇒ Object
201 202 203 |
# File 'lib/inkling_api.rb', line 201 def delete_membership(membership_id) delete("memberships/#{membership_id}.xml", :content_type => 'application/xml') end |
#get(path, params = nil) ⇒ Object
103 104 105 106 107 |
# File 'lib/inkling_api.rb', line 103 def get(path, params = nil) raw = params && params.delete(:raw) response = super raw ? response.env[:raw_body] : response.body end |
#get_token_for(membership_id) ⇒ Object
205 206 207 |
# File 'lib/inkling_api.rb', line 205 def get_token_for(membership_id) post("memberships/#{membership_id}/tokens.xml", '', :content_type => 'application.xml') end |
#market(market_id, *args) ⇒ Object
139 140 141 |
# File 'lib/inkling_api.rb', line 139 def market(market_id, *args) get("markets/#{market_id}.xml", *args) end |
#markets(*args) ⇒ Object
143 144 145 |
# File 'lib/inkling_api.rb', line 143 def markets(*args) get("markets.xml", *args) end |
#me ⇒ Object
Get’s membership of current logged in user
177 178 179 |
# File 'lib/inkling_api.rb', line 177 def me # Get's membership of current logged in user get("memberships/me.xml") end |
#membership(member_id, *args) ⇒ Object
173 174 175 |
# File 'lib/inkling_api.rb', line 173 def membership(member_id, *args) get("memberships/#{member_id}.xml", *args) end |
#memberships(*args) ⇒ Object
169 170 171 |
# File 'lib/inkling_api.rb', line 169 def memberships(*args) get("memberships.xml", *args) end |
#new_market(question, class_type, ends_at, tag_list) ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/inkling_api.rb', line 147 def new_market(question, class_type, ends_at, tag_list) market_data = { :'name' => question, :'class-type' => class_type, :'ends-at' => ends_at, :'tag-list' => tag_list } post("markets.xml", market_data.to_xml(:root => "market"), :content_type => 'application/xml') end |
#positions(membership_id) ⇒ Object
213 214 215 |
# File 'lib/inkling_api.rb', line 213 def positions(membership_id) get("memberships/#{membership_id}/trades.xml") end |
#post(path, payload, params = nil) ⇒ Object
109 110 111 112 113 |
# File 'lib/inkling_api.rb', line 109 def post(path, payload, params = nil) raw = params && params.delete(:raw) response = super raw ? response.env[:raw_body] : response.body end |
#prices(*args) ⇒ Object
209 210 211 |
# File 'lib/inkling_api.rb', line 209 def prices(*args) get("prices.xml", *args) end |
#publish(path, params = nil) ⇒ Object
127 128 129 130 131 |
# File 'lib/inkling_api.rb', line 127 def publish(path, params = nil) raw = params && params.delete(:raw) response = super raw ? response.env[:raw_body] : response.body end |
#publish_market(market_id) ⇒ Object
165 166 167 |
# File 'lib/inkling_api.rb', line 165 def publish_market(market_id) publish("markets/#{market_id}.xml", :content_type => 'application/xml') end |
#put(path, payload, params = nil) ⇒ Object
115 116 117 118 119 |
# File 'lib/inkling_api.rb', line 115 def put(path, payload, params = nil) raw = params && params.delete(:raw) response = super raw ? response.env[:raw_body] : response.body end |
#quote(stock_id, membership_id, quantity) ⇒ Object
260 261 262 263 264 265 |
# File 'lib/inkling_api.rb', line 260 def quote(stock_id, membership_id, quantity) quote_data = { :'quantity' => quantity, :'membership_id' => membership_id } post("stocks/#{stock_id}/trades/quote.xml", quote_data.to_xml(:root => "trade"), :content_type => 'application/xml') end |
#refund(path, params = nil) ⇒ Object
133 134 135 136 137 |
# File 'lib/inkling_api.rb', line 133 def refund(path, params = nil) raw = params && params.delete(:raw) response = super raw ? response.env[:raw_body] : response.body end |
#trades ⇒ Object
249 250 251 |
# File 'lib/inkling_api.rb', line 249 def trades get("memberships/all/trades.xml") end |
#update_answer(stock_id, answer, symbol, starting_price) ⇒ Object
228 229 230 231 232 233 234 |
# File 'lib/inkling_api.rb', line 228 def update_answer(stock_id, answer, symbol, starting_price) answer_data = { :'name' => answer, :'symbol' => symbol, :'starting-price' => starting_price } put("stocks/#{stock_id}.xml", answer_data.to_xml(:root => "stock"), :content_type => 'application/xml') end |
#update_balance(balance_value, membership_id) ⇒ Object
196 197 198 199 |
# File 'lib/inkling_api.rb', line 196 def update_balance(balance_value, membership_id) balance_data = { :'value' => balance_value } put("memberships/#{membership_id}/balance.xml", balance_data.to_xml(:root => "balance"), :content_type => 'application/xml') end |
#update_market(market_id, question) ⇒ Object
156 157 158 159 |
# File 'lib/inkling_api.rb', line 156 def update_market(market_id, question) market_data = { :'name' => question } put("markets/#{market_id}.xml", market_data.to_xml(:root => "market"), :content_type => 'application/xml') end |
#update_membership(first_name, last_name, membership_id) ⇒ Object
191 192 193 194 |
# File 'lib/inkling_api.rb', line 191 def update_membership(first_name, last_name, membership_id) membership_data = { :'first-name' => first_name, :'last-name' => last_name } put("memberships/#{membership_id}.xml", membership_data.to_xml(:root => "membership"), :content_type => 'application/xml') end |