Module: TexMindbody::Api
- Defined in:
- lib/tex_mindbody/api.rb,
lib/tex_mindbody/api/model.rb,
lib/tex_mindbody/api/version.rb,
lib/tex_mindbody/api/model/client.rb,
lib/tex_mindbody/api/configuration.rb,
lib/tex_mindbody/api/endpoint/client.rb,
lib/tex_mindbody/api/endpoint/usertoken.rb
Defined Under Namespace
Modules: Model
Classes: Configuration
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
Returns the value of attribute headers.
15
16
17
|
# File 'lib/tex_mindbody/api.rb', line 15
def
@headers
end
|
.logger ⇒ Object
Returns the value of attribute logger.
16
17
18
|
# File 'lib/tex_mindbody/api.rb', line 16
def logger
@logger
end
|
Class Method Details
.clients(q = {}) ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/tex_mindbody/api/endpoint/client.rb', line 4
def clients q = {}
query_opts = %i{ClientIds SearchText IsProspect LastModifiedDate}
validate_query q, query_opts
path = "#{TexMindbody::Api.config.rest_api}/client/clients"
clients = paginated_get path, 'Clients', q
clients.map {|c| TexMindbody::Api::Model::Client.new c}
end
|
18
19
20
21
|
# File 'lib/tex_mindbody/api.rb', line 18
def configure
yield config
init
end
|
.issue ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/tex_mindbody/api/endpoint/usertoken.rb', line 4
def issue
path = "#{TexMindbody::Api.config.rest_api}/usertoken/issue"
= {
"Content-Type": 'application/json',
"Api-Key": TexMindbody::Api.config.api_key,
"SiteId": TexMindbody::Api.config.site_id
}
body = {
"Username": TexMindbody::Api.config.username,
"Password": TexMindbody::Api.config.password
}
response = HTTParty.post path, :headers => , :query => {}, :body => body.to_json
raise IOError.new response if response.server_error?
raise ArgumentError.new response unless response.success?
raise RuntimeError.new response if response['AccessToken'].nil?
TexMindbody::Api.config.auth_token = response['AccessToken']
end
|
.paginated_get(path, response_item, q = {}) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/tex_mindbody/api.rb', line 58
def paginated_get path, response_item, q = {}
results = []
offset = 0
query_params = q.map { |k,v| "#{k}=#{v}"}.join('&')
query_params += '&' unless query_params.empty?
loop do
path_paginated = "#{path}?#{query_params}offset=#{offset}&limit=200"
response = HTTParty.get path_paginated, headers: @headers
raise IOError.new response if response.server_error?
raise ArgumentError.new response unless response.success?
results += response[response_item]
break if ( (response['PaginationResponse']['PageSize'] + response['PaginationResponse']['RequestedOffset'] ) == response['PaginationResponse']['TotalResults'] )
offset += 200
end
results
end
|
.validate_query(q, query_opts) ⇒ Object
54
55
56
|
# File 'lib/tex_mindbody/api.rb', line 54
def validate_query q, query_opts
raise ArgumentError.new "Invalid query parameters used #{q.keys.to_s}" unless q.keys.to_set.subset?(query_opts.to_set)
end
|