Module: Mogo24r::Utils
- Included in:
- Mogo24r
- Defined in:
- lib/mogo24r/utils.rb
Overview
Utility Module for Mogo24r. This module include URI, Net::HTTP, and Time.
Instance Method Summary collapse
-
#create_request(type, uri, use_basic_auth = false) ⇒ Object
- Description
-
create Net::HTTPRequest instance.
-
#create_uri(url_string) ⇒ Object
- Description
-
create URI instance.
-
#http_access(uri, request) ⇒ Object
- Description
-
access to mogo2-API[http://FIXME].
-
#parse_options(options) ⇒ Object
- Description
-
parse option parametors.
Instance Method Details
#create_request(type, uri, use_basic_auth = false) ⇒ Object
- Description
-
create Net::HTTPRequest instance.
- Params
-
type (:post|:get), uri URI-Instance, use_basic_auth (booleans)
- Return
-
Net::HTTPRequest-Instance
- RelatedMethods
-
create_uri, http_access
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mogo24r/utils.rb', line 30 def create_request(type, uri, use_basic_auth = false) case type when :get request = Net::HTTP::Get.new(uri.request_uri) when :post request = Net::HTTP::Post.new(uri.request_uri) end request['User-Agent'] = @user_agent request.basic_auth @email, @api_key return request end |
#create_uri(url_string) ⇒ Object
- Description
-
create URI instance.
- Params
-
url_string
- Return
-
URI-Instance
- RelatedMethods
-
parse_options, create_request, http_access
57 58 59 |
# File 'lib/mogo24r/utils.rb', line 57 def create_uri(url_string) return URI.parse(URI.escape(url_string)) end |
#http_access(uri, request) ⇒ Object
- Description
-
access to mogo2-API[http://FIXME]
- Params
-
uri (URI-Instance), request (Net::HTTPRequest-Instance)
- Return
-
Responsed XML-Document or false
- RelatedMethods
-
create_uri, create_request
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mogo24r/utils.rb', line 76 def http_access(uri, request) Net::HTTP.start(uri.host, uri.port){|http| response = http.request(request) if RUBY_VERSION.match(/^1\.9\./) response.body.force_encoding('UTF-8') end if response.code == '200' return response.body else return false end } end |
#parse_options(options) ⇒ Object
- Description
-
parse option parametors
- Params
-
options (=> value, …)
- Return
-
parsed-options (‘?param_name=value&…’)
- RelatedMethods
-
create_uri
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mogo24r/utils.rb', line 103 def () result = '' if [:since] [:since] = Time.parse([:since].to_s).httpdate end = .find_all{|option|option.last} result = '?' + .collect{|option| option.join('=') }.join('&') unless .empty? return result end |