Class: OpenQq::Gateway
- Inherits:
-
Object
- Object
- OpenQq::Gateway
- Extended by:
- Signature
- Defined in:
- lib/open_qq/gateway.rb
Direct Known Subclasses
Constant Summary collapse
- OPEN_HTTP_TRANSLATE_ERROR =
2001
Instance Attribute Summary collapse
-
#appid ⇒ Object
Returns the value of attribute appid.
-
#appkey ⇒ Object
Returns the value of attribute appkey.
-
#env ⇒ Object
Returns the value of attribute env.
Instance Method Summary collapse
-
#get(url, params = {}, options = {}) ⇒ String, Object
Unformatted string result or parsed OpenStruct instance.
-
#initialize(appid, appkey, env) ⇒ Gateway
constructor
A new instance of Gateway.
-
#post(url, params = {}, options = {}) ⇒ String, Object
Unformatted string result or parsed OpenStruct instance.
-
#wrap(http_method, url, params) ⇒ Object
wrap ‘http_method`, `url`, `params` together.
Methods included from Signature
each_pair_escape, make_callback_source, make_source, parsed_params, signature, url_escape, verify_sig
Constructor Details
#initialize(appid, appkey, env) ⇒ Gateway
Returns a new instance of Gateway.
26 27 28 29 30 |
# File 'lib/open_qq/gateway.rb', line 26 def initialize(appid, appkey, env) @appid = appid @appkey = appkey self.env = env end |
Instance Attribute Details
#appid ⇒ Object
Returns the value of attribute appid.
17 18 19 |
# File 'lib/open_qq/gateway.rb', line 17 def appid @appid end |
#appkey ⇒ Object
Returns the value of attribute appkey.
17 18 19 |
# File 'lib/open_qq/gateway.rb', line 17 def appkey @appkey end |
#env ⇒ Object
Returns the value of attribute env.
17 18 19 |
# File 'lib/open_qq/gateway.rb', line 17 def env @env end |
Instance Method Details
#get(url, params = {}, options = {}) ⇒ String, Object
Returns unformatted string result or parsed OpenStruct instance.
59 60 61 62 63 |
# File 'lib/open_qq/gateway.rb', line 59 def get(url, params = {}, = {}) parsed_params = Gateway.parsed_params( wrap(:get, url, params) ) get_request = Net::HTTP::Get.new("#{url}?#{parsed_params}") self.call( get_request, .merge(:format => params[:format]) ) end |
#post(url, params = {}, options = {}) ⇒ String, Object
Returns unformatted string result or parsed OpenStruct instance.
68 69 70 71 72 73 |
# File 'lib/open_qq/gateway.rb', line 68 def post(url, params = {}, = {}) post_request = Net::HTTP::Post.new(url) post_request.body = Gateway.parsed_params( wrap(:post, url, params) ) post_request.content_type = 'application/x-www-form-urlencoded' self.call( post_request, .merge(:format => params[:format]) ) end |
#wrap(http_method, url, params) ⇒ Object
wrap ‘http_method`, `url`, `params` together
76 77 78 79 80 |
# File 'lib/open_qq/gateway.rb', line 76 def wrap(http_method, url, params) params = params.merge(:appid => @appid) params[:sig] = Gateway.signature( "#{@appkey}&", Gateway.make_source(http_method.to_s.upcase, url, params) ) params end |