Class: Chikka::Client
- Inherits:
-
Object
- Object
- Chikka::Client
- Defined in:
- lib/chikka.rb
Constant Summary collapse
- SMSAPI_PATH =
'/smsapi/request'- DEFAULT_PARAMS =
{}
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#http ⇒ Object
Returns the value of attribute http.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#shortcode ⇒ Object
Returns the value of attribute shortcode.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #send_message(params = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/chikka.rb', line 28 def initialize( = {}) @client_id= .fetch(:client_id) { ENV.fetch('CHIKKA_CLIENT_ID') } @secret_key = .fetch(:secret_key) { ENV.fetch('CHIKKA_SECRET_KEY') } @shortcode = .fetch(:shortcode) { ENV.fetch('CHIKKA_SHORTCODE') } @mask = .fetch(:mask) { ENV.fetch('CHIKKA_MASK') } if ENV.has_key?('CHIKKA_MASK') || .has_key?(:mask) @host = .fetch(:host) { 'post.chikka.com' } @http = Net::HTTP.new(@host, Net::HTTP.https_default_port) @http.use_ssl = true DEFAULT_PARAMS[:client_id] = @client_id DEFAULT_PARAMS[:secret_key] = @secret_key DEFAULT_PARAMS[:shortcode] = @shortcode DEFAULT_PARAMS[:mask] = @mask end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
25 26 27 |
# File 'lib/chikka.rb', line 25 def client_id @client_id end |
#http ⇒ Object
Returns the value of attribute http.
25 26 27 |
# File 'lib/chikka.rb', line 25 def http @http end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
25 26 27 |
# File 'lib/chikka.rb', line 25 def secret_key @secret_key end |
#shortcode ⇒ Object
Returns the value of attribute shortcode.
25 26 27 |
# File 'lib/chikka.rb', line 25 def shortcode @shortcode end |
Instance Method Details
#send_message(params = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chikka.rb', line 44 def (params = {}) params[:message_id] = params.fetch(:message_id) { } = "SEND" if params[:request_id] = "REPLY" params[:request_cost] = params.fetch(:resquest_cost) { "FREE" } end post_params = DEFAULT_PARAMS.merge({ message_type: }.merge(params)) body = URI.encode_www_form(post_params) parse(@http.post(SMSAPI_PATH, body, {'Content-Type' => 'application/x-www-form-urlencoded'}), params[:message_id]) end |