Class: Msg91::HttpClient
- Inherits:
-
Object
- Object
- Msg91::HttpClient
- Defined in:
- lib/msg91/http_client.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#client ⇒ Object
Returns the value of attribute client.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
- #get(uri, params) ⇒ Object
-
#initialize ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(_uri, params) ⇒ Object
Constructor Details
#initialize ⇒ HttpClient
Returns a new instance of HttpClient.
6 7 8 9 10 11 12 |
# File 'lib/msg91/http_client.rb', line 6 def initialize @base_url = URI('https://api.msg91.com/') @client = Net::HTTP.new(@base_url.host, @base_url.port) @client.use_ssl = true @client.verify_mode = OpenSSL::SSL::VERIFY_NONE @headers = { 'authkey' => Msg91.configuration.auth_key, 'Content-Type' => 'application/json' } end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
4 5 6 |
# File 'lib/msg91/http_client.rb', line 4 def base_url @base_url end |
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/msg91/http_client.rb', line 3 def client @client end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/msg91/http_client.rb', line 4 def headers @headers end |
#request ⇒ Object
Returns the value of attribute request.
3 4 5 |
# File 'lib/msg91/http_client.rb', line 3 def request @request end |
Instance Method Details
#get(uri, params) ⇒ Object
14 15 16 17 18 |
# File 'lib/msg91/http_client.rb', line 14 def get(uri, params) @base_url.query = URI.encode_www_form(params) response = client.get(@base_url + uri) JSON.parse(response.read_body) end |
#post(_uri, params) ⇒ Object
20 21 22 23 |
# File 'lib/msg91/http_client.rb', line 20 def post(_uri, params) response = client.post(@base_url, params, @headers) JSON.parse(response.read_body) end |