Class: Haruna::API
- Inherits:
-
Object
- Object
- Haruna::API
- Defined in:
- lib/haruna/api.rb
Direct Known Subclasses
Constant Summary collapse
- API_VER =
config req header
1- END_POINT =
'http://125.6.189.215'- USER_AGENT =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36'- REFERER =
'http://125.6.189.215/kcs/port.swf?version=1.5.5'- ACCEPT_ENCODING =
'gzip,deflate,sdch'- ACCEPT_LANGUAGE =
'ja,en-US;q=0.8,en;q=0.6'- CONTENT_TYPE =
'application/x-www-form-urlencoded'
Instance Attribute Summary collapse
-
#conn ⇒ Object
writeonly
for testing, not really need to rewrite.
Instance Method Summary collapse
- #call(action, target, param = {}) ⇒ Object
-
#initialize(token, proxy = nil) ⇒ API
constructor
A new instance of API.
- #setup_param(param) ⇒ Object
Constructor Details
#initialize(token, proxy = nil) ⇒ API
Returns a new instance of API.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/haruna/api.rb', line 13 def initialize(token, proxy=nil) require 'faraday' @token = token @conn = Faraday.new(:url => END_POINT, :proxy => proxy) do |faraday| faraday.request :url_encoded # faraday.response :logger faraday.adapter Faraday.default_adapter end end |
Instance Attribute Details
#conn=(value) ⇒ Object (writeonly)
for testing, not really need to rewrite
24 25 26 |
# File 'lib/haruna/api.rb', line 24 def conn=(value) @conn = value end |
Instance Method Details
#call(action, target, param = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/haruna/api.rb', line 26 def call(action, target, param={}) @conn.post do |req| req.url "/kcsapi/#{action}/#{target}" req.headers['User-Agent'] = USER_AGENT req.headers['Referer'] = REFERER req.headers['Accept-Encoding'] = ACCEPT_ENCODING req.headers['Accept-Language'] = ACCEPT_LANGUAGE req.headers['Content-Type'] = CONTENT_TYPE req.body = setup_param(param) end end |
#setup_param(param) ⇒ Object
38 39 40 |
# File 'lib/haruna/api.rb', line 38 def setup_param(param) param.merge(api_verno: API_VER, api_token: @token) end |