physitrack_api 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6bfd8e250cc70a90881880b70fe82e67c47a3dc12b2701f1d79338ef327ea64b
4
+ data.tar.gz: b9bcd6ec97669a9f0cea3411dd373ec8a8e06117fe074ee1ba965442aed6229b
5
+ SHA512:
6
+ metadata.gz: 719d0ed183a367fce5b0b50d12a9b9cfb57c0032f992c923cd3834ee2405d2e36e8bfc9354626df076de780389364a944bb25fabfcc26359750ad8112590ab11
7
+ data.tar.gz: 441bcfcf41cf708198b9f03e100c78c19c92e911a0d0f6413423a2c492a7e23101f1bc6bc50aa74fc9740df6edea923d60421c9f84ec92b18ca775efba591ef5
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.10
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jzntam@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in physitrack_api.gemspec
6
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ physitrack_api (0.2.0)
5
+ activesupport (= 3.2.22)
6
+ httparty (= 0.13.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.22)
12
+ i18n (~> 0.6, >= 0.6.4)
13
+ multi_json (~> 1.0)
14
+ concurrent-ruby (1.0.5)
15
+ diff-lcs (1.3)
16
+ fakeweb (1.3.0)
17
+ httparty (0.13.5)
18
+ json (~> 1.8)
19
+ multi_xml (>= 0.5.2)
20
+ i18n (0.9.5)
21
+ concurrent-ruby (~> 1.0)
22
+ json (1.8.6)
23
+ multi_json (1.13.1)
24
+ multi_xml (0.6.0)
25
+ rake (10.5.0)
26
+ rspec (3.7.0)
27
+ rspec-core (~> 3.7.0)
28
+ rspec-expectations (~> 3.7.0)
29
+ rspec-mocks (~> 3.7.0)
30
+ rspec-core (3.7.1)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-expectations (3.7.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-mocks (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-support (3.7.1)
39
+ vcr (3.0.3)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.16)
46
+ fakeweb
47
+ physitrack_api!
48
+ rake (~> 10.0)
49
+ rspec (~> 3.0)
50
+ vcr (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 1.16.2
@@ -0,0 +1,199 @@
1
+ # PhysitrackApi
2
+
3
+ A simple Ruby library for consuming the Physitrack API. This gem provides functionality to fetch data for the practitioner such as clients, exercises, programs, templates, messages and much more. All requests were tested with the `V2` version of Physitrack's API, for more information visit their docs [here](https://staging.physitrack.com/api/v2/apidocs#/clients/get_clients).
4
+
5
+ This open source project was commissioned by the good people at [Jane Software Inc.](https://www.janeapp.com), the maker of _"the best clinic management software. ever."_ For more information goto [www.janeapp.com](https://www.janeapp.com) or feel free to send Jane an [email](mailto:seejanerun@janeapp.com).
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'physitrack_api'
14
+ ```
15
+
16
+ And then execute:
17
+ ```shell
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+ ```shell
23
+ $ gem install physitrack_api
24
+ ```
25
+
26
+ ## Ruby Version
27
+ `ruby-2.1.10 [ x86_64 ]`
28
+
29
+
30
+ ## Usage
31
+
32
+ All methods take in keyword arguments for the parameters and return a `Physitrack::Response` object. The data from the API request is stored in the `payload` attribute, the `payload` can also be access using the `data` helper method. The response object also has `status`, `code`, and `message` attributes and has a `success?` helper method.
33
+
34
+ Below is a list of all requests that can be made with this client. Begin by instantiating a client object. Takes in two key word args, the `api_key` which belongs to the practitioner and a subdomain. Use the subdomain for your account/region, ie. `us`, `uk`, `ca`, `au` or `staging`.
35
+
36
+ Use the client object to make your requests.
37
+ ```ruby
38
+ client = PhysitrackApi::Client.new(api_key: 'your_key', subdomain: 'staging')
39
+ ```
40
+
41
+ Fetch all the practitioner's clients.
42
+ ```ruby
43
+ response = client.get_all_clients
44
+
45
+ response.success? # check if the response was a success
46
+ response.payload # JSON / Hash response from Physitrack
47
+ response.data # Returns the exact same as payload
48
+ ```
49
+
50
+ Find a client.
51
+ ```ruby
52
+ client.find_client(id: 123)
53
+ ```
54
+
55
+ Create a client. For more information on how to format the data in your body, refer to **[Physitrack's API Docs](https://staging.physitrack.com/api/v2/apidocs#/clients/get_clients)**
56
+ ```ruby
57
+ params = {
58
+ external_id: 'jane_patient_id-123',
59
+ first_name: 'Jane',
60
+ last_name: 'App',
61
+ year_of_birth: 2012,
62
+ gender: 'f',
63
+ email: 'aliceson@janeapp.com',
64
+ mobile_phone: '+16043105253'
65
+ }
66
+
67
+ client.create_client(body: params)
68
+ ```
69
+
70
+ Update a client.
71
+ ```ruby
72
+ params = {
73
+ # ... whatever you want to change
74
+ }
75
+
76
+ client.update_client(id: 123, body: params)
77
+ ```
78
+
79
+ Find a program.
80
+ ```ruby
81
+ client.find_client_program(client_id: 123, access_code: 'qwertyiod')
82
+ ```
83
+
84
+ Get all programs for a client.
85
+ ```ruby
86
+ client.get_client_programs(client_id: 123)
87
+ ```
88
+
89
+ Assign a program to a client.
90
+ ```ruby
91
+ params = {
92
+ template_id: 1200,
93
+ external_id: "jane_app_patient_id",
94
+ start_date: Time.now.strftime('%Y-%m-%d'),
95
+ num_weeks: 8,
96
+ track_adherence: true,
97
+ track_pain_levels: true
98
+ }
99
+
100
+ client.assign_program(client_id: 123, body: params)
101
+ ```
102
+
103
+ Update an assigned program. This request takes in only 1 attribute `end_date`. **WARNING:** if you set `end_date` to `nil` or send params as an empty hash, the API will end the program immediately!
104
+ ```ruby
105
+ params = {
106
+ end_date: Date.today + 1.month
107
+ }
108
+
109
+ client.update_client_program(client_id: 123, access_code: 'qwertyiod', body: params)
110
+ ```
111
+
112
+ Send the client the access code to a program. Can be sent via `email` or `sms`.
113
+ ```ruby
114
+ client.resend_access_code(client_id: 123, access_code: 'qwertyiod', via: 'email')
115
+ ```
116
+
117
+ Fetch all the exercises related to a program. Pass in `pdf: true` to get a link to a pdf file.
118
+ ```ruby
119
+ client.get_client_program_exercises(client_id: 123, access_code: 'qwertyiod', pdf: false)
120
+ ```
121
+
122
+ Check on the client's progress and adherence.
123
+ ```ruby
124
+ client.get_client_program_adherence(client_id: 123, access_code: 'qwertyiod')
125
+ ```
126
+
127
+ Find client PROM.
128
+ ```ruby
129
+ client.find_client_program_prom(client_id: 123, access_code: 'qwertyiod', id: 987)
130
+ ```
131
+
132
+ Fetch all PROMs for a client.
133
+ ```ruby
134
+ client.get_all_client_program_proms(client_id: 123, access_code: 'qwertyiod')
135
+ ```
136
+
137
+ Find PROM results for a client's program.
138
+ ```ruby
139
+ client.find_client_program_prom_results(client_id: 123, access_code: 'qwertyiod', id: 987)
140
+ ```
141
+
142
+ Find a specific client message by id.
143
+ ```ruby
144
+ client.find_client_message(client_id: 123, id: 222)
145
+ ```
146
+
147
+ Fetch all messages between a client and practitioner.
148
+ ```ruby
149
+ client.get_all_client_messages(client_id: 123)
150
+ ```
151
+
152
+ Find a specific template.
153
+ ```ruby
154
+ client.find_template(id: 1200)
155
+ ```
156
+
157
+ Fetch all templates.
158
+ ```ruby
159
+ client.get_all_templates
160
+ ```
161
+
162
+ Fetch exercises.
163
+ ```ruby
164
+ client.get_all_exercises
165
+
166
+ # Optionally pass in a query keyword argument to narrow down your search
167
+
168
+ client.get_all_exercises(query: 'strength')
169
+ ```
170
+
171
+ Find a specific client event by id.
172
+ ```ruby
173
+ client.find_event(id: 777)
174
+ ```
175
+
176
+ Fetch all events.
177
+ ```ruby
178
+ client.get_all_events
179
+ ```
180
+
181
+
182
+ ## Contributing
183
+
184
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jzntam/physitrack_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
185
+
186
+ 1. Fork it ( https://github.com/jzntam/physitrack_api/fork )
187
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
188
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
189
+ 4. Push to the branch (`git push origin my-new-feature`)
190
+ 5. Create a new Pull Request
191
+
192
+
193
+ ## Code of Conduct
194
+
195
+ Everyone interacting in the PhysitrackApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jzntam/physitrack_api/blob/master/CODE_OF_CONDUCT.md).
196
+
197
+
198
+ ## Thanks
199
+ <img src="https://uploads-ssl.webflow.com/564c698e77bcae4a222a98f2/569370585110149410401703_physiapp_logo.png" width="100" alt='Physitrack'/> &nbsp; &nbsp;<img src="https://www.janeapp.com/assets/jane-header-logo@2x-2c0b48359f53a8025428ae7551a38257.png" height="40" />
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "physitrack_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require "physitrack_api/version"
2
+ require "physitrack_api/client"
3
+ require "physitrack_api/response"
@@ -0,0 +1,267 @@
1
+ require "httparty"
2
+ require 'active_support/all'
3
+
4
+ module PhysitrackApi
5
+ class Client
6
+ def initialize(api_key:, subdomain:)
7
+ raise ArgumentError.new('You must provide a Physitrack API Key') unless api_key.present?
8
+ raise ArgumentError.new('You must provide a Physitrack subdomain') unless subdomain.present?
9
+
10
+ @api_key = api_key
11
+ @subdomain = subdomain
12
+ end
13
+
14
+ # Find a single client by id
15
+ def find_client(id:)
16
+ response = get("clients/#{id}")
17
+ PhysitrackApi::Response.from(response)
18
+ end
19
+
20
+ # Fetch all clients for practitioner, recursively. Paginated request.
21
+ def get_all_clients(page: 1, clients: [])
22
+ response = get("clients?page=#{page}")
23
+
24
+ return PhysitrackApi::Response.from(response) unless response.success?
25
+
26
+ clients += response['clients']
27
+
28
+ if response['clients'].try(:size) == 200
29
+ get_all_clients(page: page + 1, clients: clients)
30
+ else
31
+ PhysitrackApi::Response.from(response, payload: { 'clients' => clients })
32
+ end
33
+ end
34
+
35
+ # Create a single client
36
+ # body = {
37
+ # external_id: Required unique id,
38
+ # first_name: Required,
39
+ # last_name: Required,
40
+ # year_of_birth: Required,
41
+ # gender: Required m or f,
42
+ # email: Optional,
43
+ # mobile_phone: Optional '+16043105253'
44
+ # }
45
+ def create_client(body:)
46
+ response = post('clients/', body: body)
47
+
48
+ PhysitrackApi::Response.from(response)
49
+ end
50
+
51
+ # Create a single client
52
+ # Uses same body structure as create_client
53
+ def update_client(id:, body:)
54
+ response = put("clients/#{id}", body: body)
55
+
56
+ PhysitrackApi::Response.from(response)
57
+ end
58
+
59
+ # Find a single program using client_id and access_code
60
+ def find_client_program(client_id:, access_code:)
61
+ response = get("clients/#{client_id}/programs/#{access_code}")
62
+
63
+ PhysitrackApi::Response.from(response)
64
+ end
65
+
66
+ # Find all programs for the client. Paginated request
67
+ def get_client_programs(client_id:, page: 1, programs: [])
68
+ response = get("clients/#{client_id}/programs?page=#{page}")
69
+
70
+ return PhysitrackApi::Response.from(response) unless response.success?
71
+
72
+ programs += response['programs']
73
+
74
+ if response['programs'].try(:size) == 200
75
+ get_client_programs(client_id: client_id, page: page + 1, programs: programs)
76
+ else
77
+ PhysitrackApi::Response.from(response, payload: { 'programs' => programs })
78
+ end
79
+ end
80
+
81
+ # Assign a program to a client
82
+ # body = {
83
+ # template_id: Required,
84
+ # external_id: Optional,
85
+ # start_date: Required 2018-06-13T00:00:00Z ISO8601 format,
86
+ # num_weeks: Optional inheirits from template,
87
+ # track_adherence: Optional inheirits from template,
88
+ # track_pain_levels: Optional inheirits from template,
89
+ # }
90
+ def assign_program(client_id:, body:)
91
+ response = post("clients/#{client_id}/programs", body: body)
92
+
93
+ PhysitrackApi::Response.from(response)
94
+ end
95
+
96
+ # Update a program that has already been assigned to a client
97
+ # If left empty, then end date is set to today, and program is ended.
98
+ # body = {
99
+ # end_date: Required 2018-06-13T00:00:00Z ISO8601 format
100
+ # }
101
+ # body = {
102
+ # end_date: nil
103
+ # }
104
+ def update_client_program(client_id:, access_code:, body:)
105
+ response = put("clients/#{client_id}/programs/#{access_code}", body: body)
106
+
107
+ PhysitrackApi::Response.from(response)
108
+ end
109
+
110
+ # Send the client the program access code, 'sms' or 'email'. Defaults to email.
111
+ def resend_access_code(client_id:, access_code:, via: 'email')
112
+ response = post("clients/#{client_id}/programs/#{access_code}/resend?via=#{via}", body: {})
113
+
114
+ PhysitrackApi::Response.from(response)
115
+ end
116
+
117
+ # Get all the exercises for a program assigned to a client
118
+ # The default format will return a hashable object containing the entire
119
+ # exercise routine for the duration of the program.
120
+ # The pdf format will return a url linking to a personalized pdf document
121
+ # containing just the exercise descriptions for the program.
122
+ def get_client_program_exercises(client_id:, access_code:, pdf: false)
123
+ pdf_file = "?format=pdf" if pdf
124
+ response = get("clients/#{client_id}/programs/#{access_code}/exercises#{pdf_file}")
125
+
126
+ PhysitrackApi::Response.from(response)
127
+ end
128
+
129
+ # Adherence & pain levels for all exercises inside this access code.
130
+ def get_client_program_adherence(client_id:, access_code:)
131
+ response = get("clients/#{client_id}/programs/#{access_code}/adherence")
132
+
133
+ PhysitrackApi::Response.from(response)
134
+ end
135
+
136
+ # Find a PROM assigned to a program
137
+ def find_client_program_prom(client_id:, access_code:, id:)
138
+ response = get("clients/#{client_id}/programs/#{access_code}/proms/#{id}")
139
+
140
+ PhysitrackApi::Response.from(response)
141
+ end
142
+
143
+ # Get all PROMS attached to a program
144
+ def get_all_client_program_proms(client_id:, access_code:)
145
+ response = get("clients/#{client_id}/programs/#{access_code}/proms")
146
+
147
+ PhysitrackApi::Response.from(response)
148
+ end
149
+
150
+ # Find a PROM results for a client's program
151
+ def find_client_program_prom_results(client_id:, access_code:, id:)
152
+ response = get("clients/#{client_id}/programs/#{access_code}/proms/#{id}/results")
153
+
154
+ PhysitrackApi::Response.from(response)
155
+ end
156
+
157
+ # Find a single message for a client by id
158
+ def find_client_message(client_id:, id:)
159
+ response = get("clients/#{client_id}/messages/#{id}")
160
+
161
+ PhysitrackApi::Response.from(response)
162
+ end
163
+
164
+ # Get all messages associated with the client
165
+ def get_all_client_messages(client_id:)
166
+ response = get("clients/#{client_id}/messages")
167
+
168
+ PhysitrackApi::Response.from(response)
169
+ end
170
+
171
+ # Find a template by it's id. ie. program, workout, routine etc.
172
+ def find_template(id:)
173
+ response = get("templates/#{id}")
174
+
175
+ PhysitrackApi::Response.from(response)
176
+ end
177
+
178
+ # Get all templates that are available to the practitioner.
179
+ def get_all_templates(page: 1, templates: [])
180
+ response = get("templates?page=#{page}")
181
+
182
+ return PhysitrackApi::Response.from(response) unless response.success?
183
+
184
+ templates += response['templates']
185
+
186
+ if response['templates'].try(:size) == 200
187
+ get_all_templates(page: page + 1, templates: templates)
188
+ else
189
+ PhysitrackApi::Response.from(response, payload: { 'templates' => templates })
190
+ end
191
+ end
192
+
193
+ # Find all programs for the client. This method can take an optional query
194
+ # keyword argument that will search exercises based on the name
195
+ def get_all_exercises(query: nil, page: 1, exercises: [])
196
+ search_params = "name=#{query}&" if query
197
+ query_string = "#{search_params}page=#{page}"
198
+ response = get("exercises?#{query_string}")
199
+
200
+ return PhysitrackApi::Response.from(response) unless response.success?
201
+
202
+ exercises += response['exercises']
203
+
204
+ if response['exercises'].try(:size) == 200
205
+ get_all_exercises(query: query, page: page + 1, exercises: exercises)
206
+ else
207
+ PhysitrackApi::Response.from(response, payload: { 'exercises' => exercises })
208
+ end
209
+ end
210
+
211
+ # Find a event by it's id.
212
+ def find_event(id:)
213
+ response = get("events/#{id}")
214
+
215
+ PhysitrackApi::Response.from(response)
216
+ end
217
+
218
+ # Get all events that occured on the practitioner's account.
219
+ def get_all_events(page: 1, events: [])
220
+ response = get("events?page=#{page}")
221
+
222
+ return PhysitrackApi::Response.from(response) unless response.success?
223
+
224
+ events += response['events']
225
+
226
+ if response['events'].try(:size) == 200
227
+ get_all_events(page: page + 1, events: events)
228
+ else
229
+ PhysitrackApi::Response.from(response, payload: { 'events' => events })
230
+ end
231
+ end
232
+
233
+ private
234
+
235
+ def base_url
236
+ "https://#{@subdomain}.physitrack.com/api/v2/"
237
+ end
238
+
239
+ def default_headers
240
+ {
241
+ 'accept' => 'application/json',
242
+ 'Content-Type' => 'application/json',
243
+ 'X-Api-Key' => "#{@api_key}"
244
+ }
245
+ end
246
+
247
+ def get(path)
248
+ HTTParty.get("#{base_url}#{path}",
249
+ headers: default_headers
250
+ )
251
+ end
252
+
253
+ def post(path, body:)
254
+ HTTParty.post("#{base_url}#{path}",
255
+ headers: default_headers,
256
+ body: body.to_json
257
+ )
258
+ end
259
+
260
+ def put(path, body:)
261
+ HTTParty.put("#{base_url}#{path}",
262
+ headers: default_headers,
263
+ body: body.to_json
264
+ )
265
+ end
266
+ end
267
+ end
@@ -0,0 +1,49 @@
1
+ module PhysitrackApi
2
+ class Response
3
+ attr_reader :payload, :status, :code, :message
4
+
5
+ def self.from(http_response, payload: nil)
6
+ payload = payload || http_response.to_h
7
+ status = http_response.success?
8
+ code = http_response.code
9
+ message = http_response.message
10
+
11
+ new(payload: payload, status: status, code: code, message: message)
12
+ end
13
+
14
+ def initialize(payload:, status:, code:, message:)
15
+ @payload = payload
16
+ @status = status
17
+ @code = code
18
+ @message = message
19
+ end
20
+
21
+ def success?
22
+ @status
23
+ end
24
+
25
+ def attributes
26
+ @payload.keys
27
+ end
28
+
29
+ def data
30
+ @payload
31
+ end
32
+
33
+ def method_missing(method_name, *args, &block)
34
+ return super unless @payload.is_a?(Hash)
35
+
36
+ if @payload.has_key?(method_name.to_s)
37
+ @payload.fetch(method_name.to_s)
38
+ else
39
+ super
40
+ end
41
+ end
42
+
43
+ def respond_to_missing?(method_name, include_private = false)
44
+ return super unless @payload.is_a?(Hash)
45
+
46
+ @payload.has_key?(method_name.to_s) || super
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module PhysitrackApi
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "physitrack_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "physitrack_api"
8
+ spec.version = PhysitrackApi::VERSION
9
+ spec.authors = ["Jason"]
10
+ spec.email = ["jzntam@gmail.com"]
11
+
12
+ spec.summary = "A simple Ruby wrapper for consuming the Physitrack API"
13
+ spec.homepage = "https://www.github.com/jzntam/physitrack_client"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against " \
21
+ "public gem pushes."
22
+ end
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "httparty", "0.13.5"
34
+ spec.add_dependency "activesupport", "3.2.22"
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "vcr", "~> 3.0"
39
+ spec.add_development_dependency "fakeweb"
40
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: physitrack_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.22
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.22
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fakeweb
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - jzntam@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/physitrack_api.rb
129
+ - lib/physitrack_api/client.rb
130
+ - lib/physitrack_api/response.rb
131
+ - lib/physitrack_api/version.rb
132
+ - physitrack_api.gemspec
133
+ homepage: https://www.github.com/jzntam/physitrack_client
134
+ licenses: []
135
+ metadata:
136
+ allowed_push_host: https://rubygems.org
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.7.7
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: A simple Ruby wrapper for consuming the Physitrack API
157
+ test_files: []