Class: AccountApi
Instance Method Summary collapse
- #config_swagger ⇒ Object
- #create_api_key_secret ⇒ Object
-
#get_balance(opts = {}) ⇒ Object
Get a summary of your account balance.
-
#initialize(api_key, api_secret) ⇒ AccountApi
constructor
apiInvoker = APIInvoker.
Constructor Details
#initialize(api_key, api_secret) ⇒ AccountApi
apiInvoker = APIInvoker
7 8 9 10 11 12 13 14 15 |
# File 'lib/account_api.rb', line 7 def initialize(api_key, api_secret) @api_key = api_key @api_secret = api_secret @sms_api = SmsApi @api_key_secret = create_api_key_secret() config_swagger() end |
Instance Method Details
#config_swagger ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/account_api.rb', line 22 def config_swagger() Swagger.configure do |config| config.host = "https://api.transmitsms.com/".gsub("http://", "").gsub("https://", "").gsub("/", "") config.base_path = "/" config.format = "x-www-form-urlencoded" config.camelize_params = false end end |
#create_api_key_secret ⇒ Object
17 18 19 20 |
# File 'lib/account_api.rb', line 17 def create_api_key_secret() api_key_secret = Base64.strict_encode64("#{@api_key}:#{@api_secret}") "Basic #{api_key_secret}" end |
#get_balance(opts = {}) ⇒ Object
Get a summary of your account balance.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/account_api.rb', line 35 def get_balance (opts={}) query_param_keys = [] headerParams = {} # set default values and merge with input = { }.merge(opts) #resource path path = "/get-balance.json".sub('{format}','json') # pull querystring keys from options queryopts = .select do |key,value| query_param_keys.include? key end # header parameters headers = {} _header_accept = 'application/json' if _header_accept != '' headerParams['Accept'] = _header_accept end _header_content_type = ['application/x-www-form-urlencoded'] headerParams['Content-Type'] = _header_content_type.length > 0 ? _header_content_type[0] : 'application/json' headers[:'Authorization'] = @api_key_secret # http body (model) post_body = nil # form parameters form_parameter_hash = {} Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make end |