Class: ClickSend::REST::Client
- Inherits:
-
Object
- Object
- ClickSend::REST::Client
- Defined in:
- lib/click_send/rest/client.rb
Overview
The ClickSend::REST::Client class stores information related to authentication such as username and api key.
Instantiate a client like this:
@client = ClickSend::REST::Client.new(:username => username, :api_key => api_key)
You can configure opts to talk to clicksend api via non secure layer. By default this is set as true, you would need to explicitly set this parameter to false if you need to.
@client = ClickSend::REST::Client.new(:username => username, :api_key => api_key, :use_ssl => false)
Once you have a client object you can use it to communicate with clicksend api.
@client..send(:to => '+919999999999', :message => 'Hello from ClickSend')
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#site_url ⇒ Object
readonly
Returns the value of attribute site_url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#account_balance(opts = {}) ⇒ Object
Direct method to get account balance using ClickSend API.
-
#delivery_report ⇒ Object
Direct method to get delivery reports for sent messages using ClickSend API.
-
#initialize(opts = {}) ⇒ Client
constructor
Instantiate a new Faraday client to talk to ClickSend.
-
#inspect ⇒ Object
:nodoc:.
Constructor Details
#initialize(opts = {}) ⇒ Client
Instantiate a new Faraday client to talk to ClickSend. The opts parameter is a hash of connection configuration options. the following keys are supported:
:username => 'username'
The username provided by clicksend. In case you don’t have one, signup on clicksend.com to get it.
:api_key => 'password'
The api_key provided by clicksend. You can find this under Manage API Users in Account Settings.
:use_ssl => false
Define if you need a secure or a non secure connection. Defaults to secure, need to override if one needs to connect via a non-secure connection.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/click_send/rest/client.rb', line 42 def initialize(opts={}) opts.merge!(use_ssl: true) @username, @api_key = opts[:username], opts[:api_key] @host = 'api.clicksend.com' @site_url = (opts[:use_ssl] ? 'https://' : 'http://') + @host @connection = Faraday.new(:url => @site_url) @connection.basic_auth username, api_key = ClickSend::REST::Sms.new(@connection) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
23 24 25 |
# File 'lib/click_send/rest/client.rb', line 23 def api_key @api_key end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
21 22 23 |
# File 'lib/click_send/rest/client.rb', line 21 def connection @connection end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
21 22 23 |
# File 'lib/click_send/rest/client.rb', line 21 def end |
#site_url ⇒ Object (readonly)
Returns the value of attribute site_url.
21 22 23 |
# File 'lib/click_send/rest/client.rb', line 21 def site_url @site_url end |
#username ⇒ Object
Returns the value of attribute username.
23 24 25 |
# File 'lib/click_send/rest/client.rb', line 23 def username @username end |
Instance Method Details
#account_balance(opts = {}) ⇒ Object
Direct method to get account balance using ClickSend API.
64 65 66 67 |
# File 'lib/click_send/rest/client.rb', line 64 def account_balance(opts={}) @account_balance = ClickSend::REST::AccountBalance.new(@connection) @account_balance.all(opts) end |
#delivery_report ⇒ Object
Direct method to get delivery reports for sent messages using ClickSend API.
57 58 59 60 |
# File 'lib/click_send/rest/client.rb', line 57 def delivery_report @delivery_report = ClickSend::REST::DeliveryReport.new(@connection) @delivery_report.all end |
#inspect ⇒ Object
:nodoc:
69 70 71 |
# File 'lib/click_send/rest/client.rb', line 69 def inspect # :nodoc: "#<ClickSend::REST::Client:0x007fc3eb08df48 @api_key=#{@api_key}, @username=#{@username}, @host=#{@host}, @site_url=#{@site_url}" end |