rallio 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 729f2d4f0b9082fa4c434fa5c330a6784c23bbd8
4
- data.tar.gz: f3ba57fc036f2d9a171cb0fe8d2c38905e0e48eb
3
+ metadata.gz: 8b601ef0809d471e7bf37312a8a67ed74556ea94
4
+ data.tar.gz: 582c8fedf7245d6e3f598a22bdcd37fc66be48fe
5
5
  SHA512:
6
- metadata.gz: b614a404effdec5976423126b7ba597e6a95c35b69f24934f54ee16d95f867cd421f699cbea9ecf1069646b3a6ee3823d451aa22d0d4255bc8c3da52702595c2
7
- data.tar.gz: ae6659df5d599925db6d9b01a6580d4cc0e0d9953fa4dd273e4253504898aa8ff59f73fef1d1a3625e8d9d89fe82c659f577f60f95a91c5291b32d50008a40ec
6
+ metadata.gz: 2544c8ab2c57dec681956f97d5f845c030f474725e6d0acd55f41b0c12403e015a37efd482ac94223e1eb5984f43e6a533be605dbb36f1c477627f51a9e3949c
7
+ data.tar.gz: b416734a6a656be1cd74c64d725a159d75fa19f428dd9d48ab20e196deb59757518b82910638262ce5ee30f3bdf222028d4765ca56b76bd1bfdc3f9d1713d8ea
data/README.md CHANGED
@@ -54,23 +54,36 @@ Rallio::User.accessible_users
54
54
  # [<Rallio::User:0x007fc325b36808 @id=100, @email="bob@yourcompany.com", @first_name="Bob", @last_name="Anderson", @accounts=[], @franchisors=[]>]
55
55
  ```
56
56
 
57
- #### #sign_on_tokens
57
+ #### .create
58
+
59
+ Creates a new user on the Rallio platform.
60
+
61
+ ```ruby
62
+ # To create a user a hash with email, first_name and last_name keys must be
63
+ # supplied.
64
+ Rallio::User.create(user: { email: 'me@example.com', first_name: 'John', last_name: 'Doe' })
65
+ # => { user: { id: 100, first_name: 'John', last_name: 'Doe', email: 'me@example.com' } }
66
+ ```
67
+
68
+ #### #sign_on_token
58
69
 
59
70
  With an instantiated user object you can call to get a single sign-on token
60
- for the given user.
71
+ for the given user. These tokens last for 5 minutes and allow the user to be
72
+ signed into the Rallio platform by visiting the given url.
61
73
 
62
74
  ```ruby
63
75
  user
64
76
  # => <Rallio::User @id=100, @email="bob@yourcompany.com", @first_name="Bob", @last_name="Anderson", @accounts=[], @franchisors=[]>
65
77
 
66
- user.sign_on_tokens
78
+ user.sign_on_token
67
79
  # => <Rallio::SignOnToken @token="15ad86b2ede6", @expires_at=#<DateTime: 2015-04-16T23:5...,321000000n),+0s,2299161j)>, @url="https://app.rallio.com/api/internal/sign_on_tokens/15ad86b2ede6">
68
80
  ```
69
81
 
70
82
  #### #access_token
71
83
 
72
84
  With an instantiated user object you can call to get an access token for the
73
- given user.
85
+ given user. These access tokens do not expire at the moment so it is recommended
86
+ that you store this and reuse the token.
74
87
 
75
88
  ```ruby
76
89
  user
@@ -82,6 +95,9 @@ user.access_token
82
95
 
83
96
  #### #me
84
97
 
98
+ **NOTE:** This endpoint is in the docs but it appears it may not be implemented.
99
+ This will remain here until that is cleared up.
100
+
85
101
  This calls out and gets the user info for a given id. All that is needed is to
86
102
  instantiate an instance with a valid user id an calling me will pull the rest
87
103
  of the information.
@@ -131,6 +147,59 @@ access_token = Rallio::AccessToken.new(access_token: '4a25dd89e50bd0a0db1eeae658
131
147
  access_token.destroy # => true
132
148
  ```
133
149
 
150
+ ### Account
151
+
152
+ These gives access to account info that a user has access to. In order to query
153
+ the API using this class you will first need a user access token.
154
+
155
+ ```ruby
156
+ user.access_token
157
+ # => <Rallio::AccessToken @access_token="4a25dd89e50bd0a0db1eeae65864fe6b", @user_id=100, @expires_at=nil, @scopes="user_info basic_access">
158
+ ```
159
+
160
+ #### .reviews
161
+
162
+ This is a convenience method to get reviews for a given account. All that is
163
+ needed is a `Rallio::Account` object instantiated with a valid account id. This
164
+ calls the `Rallio::Review.all` method to get reviews.
165
+
166
+ ```ruby
167
+ account = Rallio::Account.new(id: 9397)
168
+ # => <Rallio::Account:0x007ff4d8160f60 @id=9397, @name=nil>
169
+
170
+ account.reviews(access_token: user.access_token)
171
+ # => [<Rallio::Review:0x007fcf402de8f0 @access_token="4a25dd89e50bd0a0db1eeae65864fe6b", @id=227704, @account_id=9397, @account_name="Rally-O Tires New York", @network="facebook", @posted_at=#<DateTime: 2017-02-21T23:12:33+00:00 ((2457806j,83553s,0n),+0s,2299161j)>, @user_name="Andy Bobson", @user_image="https://graph.facebook.com/100009872044695/picture", @rating=5.0, @message="This is my favourite place to buy tires!", @comments=[{:user_name=>"Rally-O Tires New York", :user_image=>"https://graph.facebook.com/113397275345614/picture", :message=>"Thanks for the 5 star review!", :created_at=>"2017-02-22T00:49:53.000+00:00"}], @liked=true, @url="https://www.facebook.com/123123123", @can_reply=true, @location_name="Visiting Angels Newburyport MA", @location_image_url="https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/16266055_1428821143803214_8378119243787669723_n.jpg?oh=3268e6e30474a0aa488cfd896a6d6c06&oe=59357742", @review_reply=nil, @review_reply_at=nil>]
172
+ ```
173
+
174
+ ### Review
175
+
176
+ #### .all
177
+
178
+ This calls out to get all reviews for a given account or franchisor.
179
+
180
+ ```ruby
181
+ # type: can be either of :accounts or :franchisors
182
+ # id: is the id for the account or franchisor
183
+ # access_token: is the access token for a Rallio::User
184
+ reviews = Rallio::Review.all(type: :accounts, id: 9397, access_token: user.access_token)
185
+ # => [<Rallio::Review:0x007fcf402de8f0 @access_token="4a25dd89e50bd0a0db1eeae65864fe6b", @id=227704, @account_id=9397, @account_name="Rally-O Tires New York", @network="facebook", @posted_at=#<DateTime: 2017-02-21T23:12:33+00:00 ((2457806j,83553s,0n),+0s,2299161j)>, @user_name="Andy Bobson", @user_image="https://graph.facebook.com/100009872044695/picture", @rating=5.0, @message="This is my favourite place to buy tires!", @comments=[{:user_name=>"Rally-O Tires New York", :user_image=>"https://graph.facebook.com/113397275345614/picture", :message=>"Thanks for the 5 star review!", :created_at=>"2017-02-22T00:49:53.000+00:00"}], @liked=true, @url="https://www.facebook.com/123123123", @can_reply=true, @location_name="Visiting Angels Newburyport MA", @location_image_url="https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/16266055_1428821143803214_8378119243787669723_n.jpg?oh=3268e6e30474a0aa488cfd896a6d6c06&oe=59357742", @review_reply=nil, @review_reply_at=nil>]
186
+ ```
187
+
188
+ #### #reply
189
+
190
+ To reply to a review you need a Review object with and id and access_token
191
+ passed in. Then you can just call the `Rallio::Review#reply` method with the
192
+ text of your reply. **NOTE:** if you are using a review object obtained from a
193
+ call to `Rallio::Review.all` the access_token is populated for you.
194
+
195
+ ```ruby
196
+ review = Rallio::Review.new(access_token: '4a25dd89e50bd0a0db1eeae65864fe6b', id: 227704)
197
+ # =><Rallio::Review:0x007fcf402de8f0 @access_token="4a25dd89e50bd0a0db1eeae65864fe6b", @id=227704, @account_id=nil, @account_name=nil, @network=nil, @posted_at=nil, @user_name=nil, @user_image=nil, @rating=nil, @message=nil, @comments=[], @liked=nil, @url=nil, @can_reply=nil, @location_name=nil, @location_image_url=nil, @review_reply=nil, @review_reply_at=nil>
198
+
199
+ review.reply("This is my reply")
200
+ # => {}
201
+ ```
202
+
134
203
  ## Development
135
204
 
136
205
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -6,12 +6,12 @@ module Rallio
6
6
  attribute :scopes, String
7
7
 
8
8
  def self.create(user_id:)
9
- response = self.post("/users/#{user_id}/access_token", headers: app_credentials)
9
+ response = self.post("/users/#{user_id}/access_tokens", headers: app_credentials)
10
10
  new response.parsed_response
11
11
  end
12
12
 
13
13
  def destroy
14
- headers = { 'Authentication' => "Bearer #{access_token}" }
14
+ headers = { 'Authorization' => "Bearer #{access_token}" }
15
15
  self.class.delete('/access_token', headers: headers)
16
16
  true
17
17
  end
@@ -1,4 +1,21 @@
1
1
  module Rallio
2
- class Account < Franchisor
2
+ class Account < Base
3
+ attribute :id, Integer
4
+ attribute :name, String
5
+ attribute :short_name, String
6
+ attribute :url, String
7
+ attribute :city, String
8
+ attribute :country_code, String
9
+ attribute :time_zone, String
10
+
11
+ def reviews(access_token:)
12
+ Review.all(type: type, id: id, access_token: access_token)
13
+ end
14
+
15
+ private
16
+
17
+ def type
18
+ :accounts
19
+ end
3
20
  end
4
21
  end
data/lib/rallio/base.rb CHANGED
@@ -11,5 +11,11 @@ module Rallio
11
11
  'X-Application-Secret' => Rallio.application_secret
12
12
  }
13
13
  end
14
+
15
+ private
16
+
17
+ def app_credentials
18
+ self.class.app_credentials
19
+ end
14
20
  end
15
21
  end
@@ -1,8 +1,19 @@
1
1
  module Rallio
2
- class Franchisor
3
- include Virtus.model
2
+ class Franchisor < Account
3
+ def self.all
4
+ response = self.get('/franchisors', headers: app_credentials)
5
+ response.parsed_response['franchisors'].map { |f| new(f) }
6
+ end
4
7
 
5
- attribute :id, Integer
6
- attribute :name, String
8
+ def accounts
9
+ response = self.class.get("/franchisors/#{id}/accounts", headers: app_credentials)
10
+ response.parsed_response['accounts'].map { |a| Rallio::Account.new(a) }
11
+ end
12
+
13
+ private
14
+
15
+ def type
16
+ :franchisors
17
+ end
7
18
  end
8
19
  end
@@ -0,0 +1,32 @@
1
+ module Rallio
2
+ class Review < Base
3
+ attribute :id, Integer
4
+ attribute :account_id, Integer
5
+ attribute :account_name, String
6
+ attribute :network, String
7
+ attribute :posted_at, DateTime
8
+ attribute :user_name, String
9
+ attribute :user_image, String
10
+ attribute :rating, Float
11
+ attribute :message, String
12
+ attribute :comments, Array[Hash]
13
+ attribute :liked, Axiom::Types::Boolean
14
+ attribute :url, String
15
+ attribute :can_reply, Axiom::Types::Boolean
16
+ attribute :location_name, String
17
+ attribute :location_image_url, String
18
+ attribute :review_reply, String
19
+ attribute :review_reply_at, DateTime
20
+
21
+ def self.all(type:, id:, access_token:)
22
+ headers = { 'Authorization' => "Bearer #{access_token}" }
23
+ response = self.get("/#{type}/#{id}/reviews", headers: headers)
24
+ response.parsed_response['reviews'].map { |r| new(r) }
25
+ end
26
+
27
+ def reply(message:, access_token:)
28
+ headers = { 'Authorization' => "Bearer #{access_token}" }
29
+ self.class.post("/reviews/#{id}/reply", headers: headers, body: { message: message })
30
+ end
31
+ end
32
+ end
@@ -6,7 +6,7 @@ module Rallio
6
6
 
7
7
  def self.create(user_id:)
8
8
  response = self.post("/users/#{user_id}/sign_on_tokens", headers: app_credentials)
9
- new response.parsed_response
9
+ new response.parsed_response['sign_on_token']
10
10
  end
11
11
  end
12
12
  end
data/lib/rallio/user.rb CHANGED
@@ -7,12 +7,19 @@ module Rallio
7
7
  attribute :accounts, Array[Account]
8
8
  attribute :franchisors, Array[Franchisor]
9
9
 
10
+ attr_writer :access_token
11
+
10
12
  def self.accessible_users
11
13
  response = self.get('/accessible_users', headers: app_credentials)
12
- response.parsed_response[:users].map { |u| User.new(u) }
14
+ response.parsed_response['users'].map { |u| User.new(u) }
15
+ end
16
+
17
+ def self.create(user:)
18
+ response = self.post('/users', headers: app_credentials, body: { user: user })
19
+ new response.parsed_response['user']
13
20
  end
14
21
 
15
- def sign_on_tokens
22
+ def sign_on_token
16
23
  SignOnToken.create(user_id: id)
17
24
  end
18
25
 
@@ -20,11 +27,29 @@ module Rallio
20
27
  @access_token ||= AccessToken.create(user_id: id)
21
28
  end
22
29
 
23
- def me
24
- headers = { 'Authentication' => "Bearer #{access_token.access_token}" }
25
- response = self.class.get('/users/me', headers: headers)
26
- self.attributes = response.parsed_response
27
- self
30
+ def account_ownerships
31
+ response = self.class.get('/account_ownerships', headers: user_credentials)
32
+ response.parsed_response
33
+ end
34
+
35
+ def franchisor_ownerships
36
+ response = self.class.get('/franchisor_ownerships', headers: user_credentials)
37
+ response.parsed_response
38
+ end
39
+
40
+ # Initially this endpoint was in the API docs but it appears it may not be
41
+ # implemented. This is here until that gets cleared up.
42
+ #
43
+ # def me
44
+ # response = self.class.get('/users/me', headers: user_credentials)
45
+ # self.attributes = response.parsed_response
46
+ # self
47
+ # end
48
+
49
+ private
50
+
51
+ def user_credentials
52
+ { 'Authorization' => "Bearer #{access_token.access_token}" }
28
53
  end
29
54
  end
30
55
  end
@@ -1,3 +1,3 @@
1
1
  module Rallio
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rallio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Guzman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-07 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -144,6 +144,7 @@ files:
144
144
  - lib/rallio/account.rb
145
145
  - lib/rallio/base.rb
146
146
  - lib/rallio/franchisor.rb
147
+ - lib/rallio/review.rb
147
148
  - lib/rallio/sign_on_token.rb
148
149
  - lib/rallio/user.rb
149
150
  - lib/rallio/version.rb