Class: Textmagic::REST::Client
- Inherits:
-
Object
- Object
- Textmagic::REST::Client
- Includes:
- Utils
- Defined in:
- lib/textmagic-ruby/rest/client.rb
Constant Summary collapse
- HTTP_HEADERS =
{ 'Accept' => 'application/json', 'Accept-Charset' => 'utf-8', 'Accept-Language' => 'en-us', 'User-Agent' => "textmagic-ruby.#{Textmagic::REST::VERSION}" }
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(username = nil, token = nil, host = 'https://rest.textmagic.com/api/v2') ⇒ Client
constructor
Create a new TextMagic APIv2 REST HTTP client.
-
#inspect ⇒ Object
:nodoc:.
- #ping ⇒ Object
Methods included from Utils
#key_map, #resource, #to_camel_case, #to_underscore_case
Constructor Details
#initialize(username = nil, token = nil, host = 'https://rest.textmagic.com/api/v2') ⇒ Client
Create a new TextMagic APIv2 REST HTTP client.
Example:
@client = Textmagic::REST::Client.new username, token
username: 'my_textmagic_username'
TextMagic account’s username. Can be found here: my.textmagic.com/online/account/details
token: 'my_textmagic_apiv2_token'
TextMagic account’s token. Can be found here: my.textmagic.com/online/api/rest-api/keys
host: 'https://api.textmagictesting.com'
The domain to which you’d like the client to make HTTP requests. Useful for testing. Defaults to ‘rest.textmagic.com’.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/textmagic-ruby/rest/client.rb', line 29 def initialize(username=nil, token=nil, host='https://rest.textmagic.com/api/v2') @username = username @token = token @host = host if @username.nil? || @token.nil? raise ArgumentError, 'Username and token are required' end setup_connection setup_resources end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/textmagic-ruby/rest/client.rb', line 6 def host @host end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/textmagic-ruby/rest/client.rb', line 6 def token @token end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
6 7 8 |
# File 'lib/textmagic-ruby/rest/client.rb', line 6 def username @username end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
41 42 43 |
# File 'lib/textmagic-ruby/rest/client.rb', line 41 def inspect # :nodoc: "<#{self.class} @username=#{@username}>" end |
#ping ⇒ Object
70 71 72 73 74 |
# File 'lib/textmagic-ruby/rest/client.rb', line 70 def ping path = 'ping' response = self.get "/#{path}", {} response[path] end |