todaysplan 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/todays_plan.rb +1 -1
- data/lib/todays_plan/{athlete.rb → user.rb} +42 -21
- data/lib/todays_plan/version.rb +1 -1
- data/spec/fixtures/{athletes → users}/accept_response.json +0 -0
- data/spec/fixtures/{athletes → users}/delegates_response.json +0 -0
- data/spec/fixtures/{athletes → users}/invite_response.json +0 -0
- data/spec/fixtures/{athletes → users}/register_response.json +0 -0
- data/spec/fixtures/{athletes → users}/search_response.json +0 -0
- data/spec/todays_plan/{athlete_spec.rb → user_spec.rb} +47 -39
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 282b2cf2f7d630c1ac5b3d5abc7a0af9a256c97f
|
4
|
+
data.tar.gz: f9e2c2653716d8407c4f3e3829168191170374e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb494b63767c70fa28c649abd389400bef271cfc8bbfac8ebace68c7d616d840bf680b73ece5ca07c704c4401a70b73de96f11a5bc42b48505b7ac209fbabcb4
|
7
|
+
data.tar.gz: 93fdbf177e80b1fae7cbf1b13ec07ad4c01f4bc1fce2b87b20ad07193bee45a49fb70f4e55d8dbaa45fae28ba0d1a8e6b224c7e32392d5eb02a2e361c7bcc7dc
|
data/lib/todays_plan.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module TodaysPlan
|
2
2
|
# Uses the TodaysPlan API for workouts and athlete information
|
3
3
|
|
4
|
-
class
|
4
|
+
class User
|
5
5
|
|
6
6
|
attr_reader :id
|
7
7
|
attr_reader :name
|
@@ -28,51 +28,72 @@ module TodaysPlan
|
|
28
28
|
|
29
29
|
# Find a single athlete
|
30
30
|
# +id+:: the athlete id
|
31
|
+
# returns User
|
31
32
|
def self.find(id)
|
32
33
|
all().find{|a| a.id==id}
|
33
34
|
end
|
34
35
|
|
35
36
|
# Find all the coaches athletes
|
36
37
|
# +client+:: the authenticated client
|
38
|
+
# returns [User]
|
37
39
|
def self.all(client = nil)
|
38
40
|
Connector.new('/users/delegates/users', client).get.map do |data|
|
39
41
|
new(data)
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
|
44
|
-
#
|
45
|
-
#
|
45
|
+
|
46
|
+
# Register a new user
|
47
|
+
# This is an unauthenticated request.
|
48
|
+
# options:
|
49
|
+
# email - email address of new user
|
46
50
|
# firstname - first name of new user
|
47
51
|
# lastname - last name of new user
|
48
52
|
# password - password of new user
|
49
|
-
#
|
50
|
-
def self.
|
51
|
-
|
53
|
+
# returns User
|
54
|
+
def self.register(options)
|
52
55
|
#preregister
|
53
56
|
response = RestClient.get("#{TodaysPlan.endpoint}/auth/preregister")
|
54
57
|
|
55
|
-
# register the user
|
56
|
-
payload = {email: options[:
|
58
|
+
# register/create the user
|
59
|
+
payload = {email: options[:email], firstname: options[:firstname],
|
57
60
|
lastname: options[:lastname], password: options[:password]}
|
58
61
|
response = RestClient.post("#{TodaysPlan.endpoint}/auth/register",payload.to_json,
|
59
62
|
{ content_type: :json})
|
60
63
|
response.body
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
new(JSON.parse(response.body))
|
65
|
+
end
|
66
|
+
|
67
|
+
# Invite delegates
|
68
|
+
# This is an authenticated request of the new user to invite the delegates (coach)
|
69
|
+
# options
|
70
|
+
# relationship - relationship of delegate, i.e coach
|
71
|
+
# state - state of invite. i.e pending_coach
|
72
|
+
# email - delegates email in todaysplan
|
73
|
+
# returns Hash of the invite
|
74
|
+
def self.invite(options, client = nil)
|
75
|
+
# new user invites coach
|
76
|
+
invite={"email"=>options[:email],"state"=> options[:state],
|
77
|
+
"relationship"=> options[:relationship]}.to_json
|
78
|
+
Connector.new('/users/delegates/invite', client).post(invite)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Accept pending invitations
|
82
|
+
# This is an authenticated request of the delegate (coach) to accept invites
|
83
|
+
# from the new user.
|
84
|
+
# queries for pending invitations and accept them.
|
85
|
+
# options
|
86
|
+
# id - id of the invite from #invite
|
87
|
+
# state - state of invite. i.e pending_coach
|
88
|
+
# returns [User]
|
89
|
+
def self.accept_invites(options, client = nil)
|
69
90
|
Connector.new('/users/delegates/search/0/100', client).
|
70
|
-
post({ "state"=>
|
71
|
-
|
72
|
-
|
91
|
+
post({ "state"=> options[:state]}.to_json)["results"].map do |data|
|
92
|
+
|
93
|
+
# accept found invite
|
94
|
+
new(Connector.new("/users/delegates/invite/accept/#{data["id"]}").get()["client"])
|
73
95
|
|
74
96
|
end
|
75
|
-
athlete
|
76
97
|
end
|
77
98
|
end
|
78
99
|
end
|
data/lib/todays_plan/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe TodaysPlan::
|
3
|
+
describe TodaysPlan::User do
|
4
4
|
|
5
|
-
let(:response){File.read("spec/fixtures/
|
5
|
+
let(:response){File.read("spec/fixtures/users/search_response.json")}
|
6
6
|
|
7
7
|
it "expect to get all athletes" do
|
8
8
|
stub_request(:get, "#{TodaysPlan.endpoint}/users/delegates/users").
|
9
9
|
with(:headers => {'Accept'=>'application/json',
|
10
10
|
'Authorization'=>'Bearer abc-123', }).
|
11
11
|
to_return(:status => 200, :body => response, :headers => {})
|
12
|
-
|
13
|
-
expect(
|
14
|
-
expect(
|
15
|
-
expect(
|
16
|
-
expect(
|
17
|
-
expect(
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(
|
21
|
-
expect(
|
12
|
+
users = TodaysPlan::User.all()
|
13
|
+
expect(users).to be_a(Array)
|
14
|
+
expect(users[0]).to be_a(TodaysPlan::User)
|
15
|
+
expect(users[0].first_name).to eq "Joe"
|
16
|
+
expect(users[0].last_name).to eq "Athlete"
|
17
|
+
expect(users[0].coach).to eq 7187033
|
18
|
+
expect(users[0].timezone).to eq "US/Mountain"
|
19
|
+
expect(users[0].id).to eq 7187033
|
20
|
+
expect(users[0].name).to eq "Joe Athlete"
|
21
|
+
expect(users[0].email).to eq "joeathlete@example.com"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "expect to get one athlete" do
|
@@ -26,19 +26,20 @@ describe TodaysPlan::Athlete do
|
|
26
26
|
with(:headers => {'Accept'=>'application/json',
|
27
27
|
'Authorization'=>'Bearer abc-123', }).
|
28
28
|
to_return(:status => 200, :body => response, :headers => {})
|
29
|
-
|
30
|
-
expect(
|
31
|
-
expect(
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
-
expect(
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
expect(
|
38
|
-
expect(
|
29
|
+
user = TodaysPlan::User.find(7187033)
|
30
|
+
expect(user).to be_a(TodaysPlan::User)
|
31
|
+
expect(user).to respond_to(:first_name)
|
32
|
+
expect(user).to respond_to(:last_name)
|
33
|
+
expect(user).to respond_to(:coach)
|
34
|
+
expect(user).to respond_to(:timezone)
|
35
|
+
expect(user).to respond_to(:id)
|
36
|
+
expect(user).to respond_to(:name)
|
37
|
+
expect(user).to respond_to(:email)
|
38
|
+
expect(user).to respond_to(:dob)
|
39
|
+
expect(user).to respond_to(:country)
|
39
40
|
end
|
40
41
|
|
41
|
-
it "
|
42
|
+
it "register user" do
|
42
43
|
options = {user_email: 'joeathlete@example.com', firstname: 'joe',
|
43
44
|
lastname: 'athlete', password:'password', coach_email: 'coach@email.com'}
|
44
45
|
# preregister
|
@@ -50,23 +51,33 @@ describe TodaysPlan::Athlete do
|
|
50
51
|
with(:body => '{"email":"joeathlete@example.com","firstname":"joe","lastname":"athlete","password":"password"}',
|
51
52
|
:headers => {'Accept'=>'*/*'}).
|
52
53
|
to_return(:status => 200,
|
53
|
-
:body => File.read("spec/fixtures/
|
54
|
+
:body => File.read("spec/fixtures/users/register_response.json"),
|
54
55
|
:headers => {})
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
|
57
|
+
user = TodaysPlan::User.register(options)
|
58
|
+
expect(user.first_name).to eq "joe"
|
59
|
+
expect(user.last_name).to eq "athlete"
|
60
|
+
expect(user.email).to eq "joeathlete@example.com"
|
61
|
+
expect(user.id).to eq(1234)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "invite delegate" do
|
65
|
+
options = { relationship: 'coach', state: 'pending_coach', email: 'coach@email.com'}
|
61
66
|
#invite the coach
|
62
67
|
stub_request(:post, "#{TodaysPlan.endpoint}/users/delegates/invite").
|
63
68
|
with(:body => '{"email":"coach@email.com","state":"pending_coach","relationship":"coach"}',
|
64
69
|
:headers => {'Accept'=>'application/json',
|
65
|
-
'Authorization'=>'Bearer abc-
|
70
|
+
'Authorization'=>'Bearer abc-123',
|
66
71
|
'Content-Type'=>'application/json'}).
|
67
72
|
to_return(:status => 200,
|
68
|
-
:body => File.read("spec/fixtures/
|
73
|
+
:body => File.read("spec/fixtures/users/invite_response.json"),
|
69
74
|
:headers => {})
|
75
|
+
invite = TodaysPlan::User.invite(options)
|
76
|
+
expect(invite["id"]).to eq 8765
|
77
|
+
end
|
78
|
+
|
79
|
+
it "accept invite" do
|
80
|
+
options = { state: 'pending_coach'}
|
70
81
|
# search for pending invites
|
71
82
|
stub_request(:post, "#{TodaysPlan.endpoint}/users/delegates/search/0/100").
|
72
83
|
with(:body => '{"state":"pending_coach"}',
|
@@ -74,19 +85,16 @@ describe TodaysPlan::Athlete do
|
|
74
85
|
'Authorization'=>'Bearer abc-123',
|
75
86
|
'Content-Type'=>'application/json'}).
|
76
87
|
to_return(:status => 200,
|
77
|
-
:body => File.read("spec/fixtures/
|
88
|
+
:body => File.read("spec/fixtures/users/delegates_response.json"),
|
78
89
|
:headers => {})
|
79
90
|
# accept invite
|
80
91
|
stub_request(:get, "#{TodaysPlan.endpoint}/users/delegates/invite/accept/98765").
|
81
92
|
with(:headers => {'Accept'=>'application/json', 'Authorization'=>'Bearer abc-123'}).
|
82
93
|
to_return(:status => 200,
|
83
|
-
:body => File.read("spec/fixtures/
|
94
|
+
:body => File.read("spec/fixtures/users/accept_response.json"),
|
84
95
|
:headers => {})
|
85
|
-
|
86
|
-
expect(
|
87
|
-
expect(athlete.last_name).to eq "athlete"
|
88
|
-
expect(athlete.email).to eq "joeathlete@example.com"
|
89
|
-
expect(athlete.id).to eq(1234)
|
96
|
+
users = TodaysPlan::User.accept_invites(options)
|
97
|
+
expect(users[0].id).to eq 7189071
|
90
98
|
end
|
91
99
|
|
92
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todaysplan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Curt Wilhelm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -92,23 +92,23 @@ files:
|
|
92
92
|
- Rakefile
|
93
93
|
- lib/todays_plan.rb
|
94
94
|
- lib/todays_plan/activity.rb
|
95
|
-
- lib/todays_plan/athlete.rb
|
96
95
|
- lib/todays_plan/client.rb
|
97
96
|
- lib/todays_plan/connector.rb
|
98
97
|
- lib/todays_plan/errors.rb
|
98
|
+
- lib/todays_plan/user.rb
|
99
99
|
- lib/todays_plan/version.rb
|
100
100
|
- spec/fixtures/activities/incomplete.json
|
101
101
|
- spec/fixtures/activities/incomplete_response.json
|
102
|
-
- spec/fixtures/
|
103
|
-
- spec/fixtures/
|
104
|
-
- spec/fixtures/
|
105
|
-
- spec/fixtures/
|
106
|
-
- spec/fixtures/
|
102
|
+
- spec/fixtures/users/accept_response.json
|
103
|
+
- spec/fixtures/users/delegates_response.json
|
104
|
+
- spec/fixtures/users/invite_response.json
|
105
|
+
- spec/fixtures/users/register_response.json
|
106
|
+
- spec/fixtures/users/search_response.json
|
107
107
|
- spec/spec_helper.rb
|
108
108
|
- spec/todays_plan/activity_spec.rb
|
109
|
-
- spec/todays_plan/athlete_spec.rb
|
110
109
|
- spec/todays_plan/client_spec.rb
|
111
110
|
- spec/todays_plan/connector_spec.rb
|
111
|
+
- spec/todays_plan/user_spec.rb
|
112
112
|
- spec/todays_plan_spec.rb
|
113
113
|
homepage: https://github.com/9ksoftware/todaysplan-ruby
|
114
114
|
licenses:
|
@@ -137,14 +137,14 @@ summary: A Ruby Library for TodaysPlan
|
|
137
137
|
test_files:
|
138
138
|
- spec/fixtures/activities/incomplete.json
|
139
139
|
- spec/fixtures/activities/incomplete_response.json
|
140
|
-
- spec/fixtures/
|
141
|
-
- spec/fixtures/
|
142
|
-
- spec/fixtures/
|
143
|
-
- spec/fixtures/
|
144
|
-
- spec/fixtures/
|
140
|
+
- spec/fixtures/users/accept_response.json
|
141
|
+
- spec/fixtures/users/delegates_response.json
|
142
|
+
- spec/fixtures/users/invite_response.json
|
143
|
+
- spec/fixtures/users/register_response.json
|
144
|
+
- spec/fixtures/users/search_response.json
|
145
145
|
- spec/spec_helper.rb
|
146
146
|
- spec/todays_plan/activity_spec.rb
|
147
|
-
- spec/todays_plan/athlete_spec.rb
|
148
147
|
- spec/todays_plan/client_spec.rb
|
149
148
|
- spec/todays_plan/connector_spec.rb
|
149
|
+
- spec/todays_plan/user_spec.rb
|
150
150
|
- spec/todays_plan_spec.rb
|