Class: Xmpush::HttpBase
- Inherits:
-
Object
- Object
- Xmpush::HttpBase
- Defined in:
- lib/xmpush/http_base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #conn ⇒ Object
- #get(url, params = {}) ⇒ Object
-
#initialize(host = "", secret_key = "", connection_adapter = :net_http, headers = {}) ⇒ HttpBase
constructor
A new instance of HttpBase.
- #post(url, body = {}) ⇒ Object
Constructor Details
#initialize(host = "", secret_key = "", connection_adapter = :net_http, headers = {}) ⇒ HttpBase
Returns a new instance of HttpBase.
8 9 10 11 12 13 |
# File 'lib/xmpush/http_base.rb', line 8 def initialize(host="", secret_key="", connection_adapter = :net_http, headers={}) @host = host @secret_key = secret_key @connection_adapter = connection_adapter @headers = headers end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/xmpush/http_base.rb', line 6 def host @host end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
6 7 8 |
# File 'lib/xmpush/http_base.rb', line 6 def secret_key @secret_key end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/xmpush/http_base.rb', line 6 def url @url end |
Instance Method Details
#conn ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/xmpush/http_base.rb', line 18 def conn headers = {authorization: "key=#{@secret_key}"}.merge(@headers) Faraday.new(:url => @host, :headers => headers) do |faraday| faraday.request :url_encoded # faraday.response :logger faraday.adapter @connection_adapter end end |
#get(url, params = {}) ⇒ Object
16 |
# File 'lib/xmpush/http_base.rb', line 16 def get(url, params={}); conn.get url, params end |
#post(url, body = {}) ⇒ Object
15 |
# File 'lib/xmpush/http_base.rb', line 15 def post(url, body={}); conn.post url, body end |