Class: GroupMe::Client
- Inherits:
-
Object
- Object
- GroupMe::Client
- Defined in:
- lib/groupme/client.rb
Constant Summary collapse
- API_BASE_URL =
'https://api.groupme.com/v3/'- API_DEFAULT_HEADER =
{ 'Content-Type': 'application/json' }.freeze
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
- #delete(path, query = {}) ⇒ Object
- #get(path, query = {}) ⇒ Object
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
- #post(path, body = {}) ⇒ Object
- #request(method, path, query: {}, body: nil) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 |
# File 'lib/groupme/client.rb', line 10 def initialize(args = {}) @access_token = args[:access_token] || GroupMe.configuration.access_token @client = HTTPClient.new(base_url: API_BASE_URL, default_header: API_DEFAULT_HEADER) end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/groupme/client.rb', line 8 def access_token @access_token end |
Instance Method Details
#delete(path, query = {}) ⇒ Object
23 24 25 |
# File 'lib/groupme/client.rb', line 23 def delete(path, query = {}) request(:delete, path, query: query) end |
#get(path, query = {}) ⇒ Object
15 16 17 |
# File 'lib/groupme/client.rb', line 15 def get(path, query = {}) request(:get, path, query: query) end |
#post(path, body = {}) ⇒ Object
19 20 21 |
# File 'lib/groupme/client.rb', line 19 def post(path, body = {}) request(:post, path, body: body) end |
#request(method, path, query: {}, body: nil) ⇒ Object
27 28 29 30 |
# File 'lib/groupme/client.rb', line 27 def request(method, path, query: {}, body: nil) response = @client.request(method, path, { token: @access_token }.merge(query), body&.to_json) [parse_response_body(response), response.status] end |