class Apiwha::Api
Constants
- API_URL
- DEFAULT_OPTIONS
Attributes
api_key[R]
Public Class Methods
new(api_key)
click to toggle source
# File lib/apiwha/api.rb, line 19 def initialize(api_key) @api_key = api_key end
Public Instance Methods
get_credit()
click to toggle source
# File lib/apiwha/api.rb, line 41 def get_credit response = RestClient.get("#{API_URL}/get_credit.php?apikey=#{@api_key}") response(response: response) end
pull_messages(params: DEFAULT_OPTIONS)
click to toggle source
# File lib/apiwha/api.rb, line 23 def pull_messages(params: DEFAULT_OPTIONS) response = RestClient.get("#{API_URL}/get_messages.php?apikey=#{@api_key}", { params: params }) response(response: response) end
send_message(text: , number: , custom_data: {})
click to toggle source
# File lib/apiwha/api.rb, line 28 def send_message(text: , number: , custom_data: {}) payload = { text: text, number: number, apikey: @api_key, custom_data: custom_data.to_json } response = RestClient.post "#{API_URL}/send_message.php?", payload response(response: response) end
Private Instance Methods
response(response: )
click to toggle source
# File lib/apiwha/api.rb, line 49 def response(response: ) return JSON.parse(response.body) if response.code.to_i == 200 raise Error.new(response) end