checkdin 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/checkdin/users.rb +37 -0
- data/lib/checkdin/version.rb +1 -1
- data/lib/checkdin/won_rewards.rb +1 -0
- data/spec/checkdin/users_spec.rb +51 -0
- metadata +1 -1
data/lib/checkdin/users.rb
CHANGED
@@ -44,5 +44,42 @@ module Checkdin
|
|
44
44
|
return_error_or_body(response)
|
45
45
|
end
|
46
46
|
|
47
|
+
# Retrieve a list of a user's authentications to external services (Facebook, Foursquare, etc.)
|
48
|
+
#
|
49
|
+
# param [Integer] id The ID of the user
|
50
|
+
|
51
|
+
def user_authentications(id)
|
52
|
+
response = connection.get("users/#{id}/authentications")
|
53
|
+
return_error_or_body(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Retrieve information about a user's specific authentication to an external service
|
57
|
+
#
|
58
|
+
# param [Integer] user_id The ID of the user
|
59
|
+
# param [Integer] id The ID of the authentication
|
60
|
+
|
61
|
+
def user_authentication(user_id, id)
|
62
|
+
response = connection.get("users/#{user_id}/authentications/#{id}")
|
63
|
+
return_error_or_body(response)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Create an authentication for a user
|
67
|
+
#
|
68
|
+
# param [Integer] id The ID of the user
|
69
|
+
# @param [Hash] options
|
70
|
+
# @option options String :provider - The name of the provider for the authentication (twitter, facebook, foursquare, linkedin, instagram)
|
71
|
+
# @option options String :uid - The user's id for the provider (on the provider's service, not your internal identifier)
|
72
|
+
# @option options String :oauth_token - The user's oauth token or access token that can be used to retrieve data on their behalf on the service.
|
73
|
+
# @option options String :oauth_token_secret - The user's oauth token secret or access token secret that is used in combination with the oauth token (required for twitter)
|
74
|
+
# @option options String :nickname - The user's nickname on the provider's service.
|
75
|
+
|
76
|
+
def create_user_authentication(id, options={})
|
77
|
+
response = connection.post do |req|
|
78
|
+
req.url "users/#{id}/authentications", options
|
79
|
+
end
|
80
|
+
return_error_or_body(response)
|
81
|
+
end
|
82
|
+
|
83
|
+
|
47
84
|
end
|
48
85
|
end
|
data/lib/checkdin/version.rb
CHANGED
data/lib/checkdin/won_rewards.rb
CHANGED
@@ -15,6 +15,7 @@ module Checkdin
|
|
15
15
|
# @param [Hash] options
|
16
16
|
# @option options Integer :campaign_id - Only return won rewards for this campaign.
|
17
17
|
# @option options Integer :user_id - Only return won rewards for this user.
|
18
|
+
# @option options Integer :promotion_id - Only return won rewards for this promotion.
|
18
19
|
# @option options Integer :limit - The maximum number of records to return.
|
19
20
|
|
20
21
|
def won_rewards(options={})
|
data/spec/checkdin/users_spec.rb
CHANGED
@@ -55,4 +55,55 @@ describe Checkdin::Users do
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
context "viewing a single user's list of authentications" do
|
60
|
+
use_vcr_cassette
|
61
|
+
let(:result) { @client.user_authentications(7835) }
|
62
|
+
|
63
|
+
it "should make a list of authentications available" do
|
64
|
+
result.authentications.collect{ |a| a.authentication.provider }.should == ["twitter","facebook","foursquare"]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should include the user's uid" do
|
68
|
+
result.authentications.collect{ |a| a.authentication.uid }.should == ["5930881311","1000038776937901","19125491"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "viewing a single user's specific authentication" do
|
73
|
+
use_vcr_cassette
|
74
|
+
let(:result) { @client.user_authentication(7835, 19479) }
|
75
|
+
|
76
|
+
it "should make a single authentication available" do
|
77
|
+
result.authentication.provider.should == "twitter"
|
78
|
+
result.authentication.uid.should == "5930881311"
|
79
|
+
result.authentication.nickname.should == "demo"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "creating an authentication" do
|
84
|
+
context "with valid parameters" do
|
85
|
+
use_vcr_cassette
|
86
|
+
let(:result) { @client.create_user_authentication(7887,
|
87
|
+
:provider => "foursquare",
|
88
|
+
:uid => "1234",
|
89
|
+
:oauth_token => "111",
|
90
|
+
:nickname => "foursquare_name") }
|
91
|
+
|
92
|
+
it "should return the new authentication's information" do
|
93
|
+
result.authentication.provider.should == "foursquare"
|
94
|
+
result.authentication.uid.should == "1234"
|
95
|
+
result.authentication.nickname.should == "foursquare_name"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "with invalid parameters" do
|
100
|
+
use_vcr_cassette
|
101
|
+
|
102
|
+
it "should return an error 400" do
|
103
|
+
expect do
|
104
|
+
@client.create_user_authentication(7887)
|
105
|
+
end.to raise_error(Checkdin::APIError, /400/)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
58
109
|
end
|