rallio 0.4.1 → 0.4.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: 04a1b0410f3446004d68353fb670ea94971bfbf2
4
- data.tar.gz: 86bf9e90c057f0a76bc23caa041d18b7f393ee38
3
+ metadata.gz: 1e09140384dd4ab0295ebfd128a49328538a8e37
4
+ data.tar.gz: a01df9d158fd7a6985f63fb7bd8b3b1506f31edb
5
5
  SHA512:
6
- metadata.gz: dc8845c14a63db683ce8eea98fbff1fb71200467aed893a18e053708a1befdebb6ed38a36619c32ff623f2bdb26805ebb5337ac4e1da3dafc9679bacb302af50
7
- data.tar.gz: fd31f9811b8c639514c0e5e5db4f39fac9743c523aba43c031e96e7cd50d4ef8ba01de4dd4e04cfb6531de81646367cd53984f3e8a0b61c1e9c1a7e97c4c937c
6
+ metadata.gz: 295ca0a315f2adf7c0c88c8e5f16e4ba24bc01657d9ae53646735e80010baa6583f54823ecc205af7d109a777b338cc5b625ae0e6ca6013251f1cbc86f8a19b7
7
+ data.tar.gz: c191d0f8bf882bf02f5d3fec612750d567d7cb486bd7f88603936b5453c2b141529e991c90a1bcff376d25508f9f7b7e21de533c859334dec46006ab1c7ce518
@@ -1,15 +1,34 @@
1
1
  module Rallio
2
+ # Represents an access token object as it comes from Rallio.
3
+ #
4
+ # @!attribute [rw] access_token
5
+ # Access token string
6
+ # @!attribute [rw] user_id
7
+ # @!attribute [rw] expires_at
8
+ # @return [DateTime, nil] expiration DateTime or nil if access token never expires
9
+ # @!attribute [rw] scopes
10
+ # List of oauth scopes for the access token
2
11
  class AccessToken < Base
3
12
  attribute :access_token, String
4
13
  attribute :user_id, Integer
5
14
  attribute :expires_at, DateTime
6
15
  attribute :scopes, String
7
16
 
17
+ # Creates new access token for user_id.
18
+ #
19
+ # NOTE: These token do not expire so it is suggested (recommended) that the
20
+ # token be cached and reused whenever possible.
21
+ #
22
+ # @param user_id [Integer]
23
+ # @return [Rallio::AccessToken]
8
24
  def self.create(user_id:)
9
25
  response = self.post("/users/#{user_id}/access_tokens", headers: app_credentials)
10
26
  new response.parsed_response
11
27
  end
12
28
 
29
+ # Destroys access_token
30
+ #
31
+ # @return [true, nil] true if successful or nil
13
32
  def destroy
14
33
  headers = { 'Authorization' => "Bearer #{access_token}" }
15
34
  self.class.delete('/access_token', headers: headers)
@@ -1,4 +1,13 @@
1
1
  module Rallio
2
+ # Represents an account object as it comes from Rallio.
3
+ #
4
+ # @!attribute [rw] id
5
+ # @!attribute [rw] name
6
+ # @!attribute [rw] short_name
7
+ # @!attribute [rw] url
8
+ # @!attribute [rw] city
9
+ # @!attribute [rw] country_code
10
+ # @!attribute [rw] time_zone
2
11
  class Account < Base
3
12
  attribute :id, Integer
4
13
  attribute :name, String
@@ -8,19 +17,33 @@ module Rallio
8
17
  attribute :country_code, String
9
18
  attribute :time_zone, String
10
19
 
11
- def reviews(access_token:)
12
- Review.all(type: type, id: id, access_token: access_token)
13
- end
14
-
20
+ # Retreives accounts.
21
+ #
22
+ # @param franchisor_id [Integer] franchisor_id to get accounts for
23
+ # @return [Array<Rallio::Account>]
15
24
  def self.for(franchisor_id:)
16
25
  response = self.get("/franchisors/#{franchisor_id}/accounts", headers: app_credentials)
17
26
  response.parsed_response['accounts'].map { |a| new a }
18
27
  end
19
28
 
29
+ # Creates an account.
30
+ #
31
+ # @param franchisor_id [Integer] franchisor_id to create account under
32
+ # @param payload [Hash]
33
+ # @option payload [Hash] :account data to create account with
34
+ # @return [Hash] hash of account created
20
35
  def self.create(franchisor_id:, payload:)
21
36
  self.post("/franchisors/#{franchisor_id}/accounts", headers: app_credentials, body: payload).parsed_response
22
37
  end
23
38
 
39
+ # Retreives reviews for the account.
40
+ #
41
+ # @param access_token [String] user access token for API access to account
42
+ # @return [Array<Rallio::Review>]
43
+ def reviews(access_token:)
44
+ Review.all(type: type, id: id, access_token: access_token)
45
+ end
46
+
24
47
  private
25
48
 
26
49
  def type
@@ -1,4 +1,11 @@
1
1
  module Rallio
2
+ # Represents an account ownership object as it comes from Rallio.
3
+ #
4
+ # @!attribute [rw] user_id
5
+ # @!attribute [rw] account_id
6
+ # @!attribute [rw] account_name
7
+ # @!attribute [rw] account_franchisor_id
8
+ # @!attribute [rw] account_franchisor_name
2
9
  class AccountOwnership < OwnershipsBase
3
10
  attribute :user_id, Integer
4
11
  attribute :account_id, Integer
@@ -6,10 +13,12 @@ module Rallio
6
13
  attribute :account_franchisor_id, Integer
7
14
  attribute :account_franchisor_name, String
8
15
 
16
+ # (see Rallio::FranchisorOwnership#self.url_segment)
9
17
  def self.url_segment
10
18
  'account_ownerships'
11
19
  end
12
20
 
21
+ # (see Rallio::FranchisorOwnership#self.response_key)
13
22
  def self.response_key
14
23
  'account_ownership'
15
24
  end
@@ -5,6 +5,10 @@ module Rallio
5
5
 
6
6
  base_uri 'https://app.rallio.com/api/v1'
7
7
 
8
+ # The credentials that can be used in the headers of any request requiring
9
+ # app level credentials
10
+ #
11
+ # @return [Hash] credentials hash
8
12
  def self.app_credentials
9
13
  {
10
14
  'X-Application-ID' => Rallio.application_id,
@@ -1,10 +1,17 @@
1
1
  module Rallio
2
2
  class Franchisor < Account
3
+ # Retreives all franchisors for a given application.
4
+ #
5
+ # @return [Array<Rallio::Franchisor>]
3
6
  def self.all
4
7
  response = self.get('/franchisors', headers: app_credentials)
5
8
  response.parsed_response['franchisors'].map { |f| new(f) }
6
9
  end
7
10
 
11
+ # Retreives all accounts for the Rallio::Franchisor
12
+ # @see Rallio::Account
13
+ #
14
+ # @return [Array<Rallio::Account>]
8
15
  def accounts
9
16
  Rallio::Account.for(franchisor_id: id)
10
17
  end
@@ -1,13 +1,24 @@
1
1
  module Rallio
2
+ # Represents a franchisor ownership as it comes from Rallio.
3
+ #
4
+ # @!attribute [rw] user_id
5
+ # @!attribute [rw] franchisor_id
6
+ # @!attribute [rw] franchisor_name
2
7
  class FranchisorOwnership < OwnershipsBase
3
8
  attribute :user_id, Integer
4
9
  attribute :franchisor_id, Integer
5
10
  attribute :franchisor_name, String
6
11
 
12
+ # Url segment used by base class to build correct endpoint.
13
+ #
14
+ # @return [String]
7
15
  def self.url_segment
8
16
  'franchisor_ownerships'
9
17
  end
10
18
 
19
+ # Key used to extract response object from API response hash.
20
+ #
21
+ # @return [String]
11
22
  def self.response_key
12
23
  'franchisor_ownership'
13
24
  end
@@ -1,16 +1,32 @@
1
1
  module Rallio
2
2
  class OwnershipsBase < Base
3
+ # Ownerships for access_token and url segment defined in class.
4
+ #
5
+ # @param access_token [String] user access token to get ownerships for
3
6
  def self.for(access_token:)
4
7
  headers = { 'Authorization' => "Bearer #{access_token}" }
5
8
  response = self.get("/#{url_segment}", headers: headers)
6
9
  response.parsed_response["#{url_segment}"].map { |a| new(a) }
7
10
  end
8
11
 
12
+ # Create new ownership.
13
+ #
14
+ # @param user_id [Integer] user id to create ownership for
15
+ # @param payload [Hash]
16
+ # @option payload [Integer] :franchisor_id franchisor to link to user_id
17
+ # @option payload [Integer] :account_id account to link to user_id
18
+ # @return [Rallio::FranchisorOwnership, Rallio::AccountOwnership]
19
+ # object representing new ownership
9
20
  def self.create(user_id:, payload:)
10
21
  response = self.post("/users/#{user_id}/#{url_segment}", headers: app_credentials, body: payload)
11
22
  new response.parsed_response["#{response_key}"]
12
23
  end
13
24
 
25
+ # Destroy ownership for user.
26
+ #
27
+ # @param user_id [Integer] user id to destory ownership for
28
+ # @param object_id [Integer] can be either a franchisor_id or an account_id
29
+ # depending on what class this is called from
14
30
  def self.destroy(user_id:, object_id:)
15
31
  self.delete("/users/#{user_id}/#{url_segment}/#{object_id}", headers: app_credentials)
16
32
  end
@@ -1,4 +1,23 @@
1
1
  module Rallio
2
+ # Represents a review object as it comes from Rallio.
3
+ #
4
+ # @!attribute [rw] id
5
+ # @!attribute [rw] account_id
6
+ # @!attribute [rw] account_name
7
+ # @!attribute [rw] network
8
+ # @!attribute [rw] posted_at
9
+ # @!attribute [rw] user_name
10
+ # @!attribute [rw] user_image
11
+ # @!attribute [rw] rating
12
+ # @!attribute [rw] message
13
+ # @!attribute [rw] comments
14
+ # @!attribute [rw] liked
15
+ # @!attribute [rw] url
16
+ # @!attribute [rw] can_reply
17
+ # @!attribute [rw] location_name
18
+ # @!attribute [rw] location_image_url
19
+ # @!attribute [rw] review_reply
20
+ # @!attribute [rw] review_reply_at
2
21
  class Review < Base
3
22
  attribute :id, Integer
4
23
  attribute :account_id, Integer
@@ -18,12 +37,23 @@ module Rallio
18
37
  attribute :review_reply, String
19
38
  attribute :review_reply_at, DateTime
20
39
 
40
+ # Retreives reviews.
41
+ #
42
+ # @param type [String] one of accounts or franchisors to get reviews for
43
+ # @param id [Integer] account or franchisor id to get reviews for
44
+ # @param access_token [String] user access token to use for authorization
45
+ # @return [Array<Rallio::Review>]
21
46
  def self.all(type:, id:, access_token:)
22
47
  headers = { 'Authorization' => "Bearer #{access_token}" }
23
48
  response = self.get("/#{type}/#{id}/reviews", headers: headers)
24
49
  response.parsed_response['reviews'].map { |r| new(r) }
25
50
  end
26
51
 
52
+ # Replies to review.
53
+ #
54
+ # @param message [String] text used for reply
55
+ # @param access_token [String] user access token to use for authorization
56
+ # @return [Hash] reply hash that was created
27
57
  def reply(message:, access_token:)
28
58
  headers = { 'Authorization' => "Bearer #{access_token}" }
29
59
  self.class.post("/reviews/#{id}/reply", headers: headers, body: { message: message })
@@ -1,9 +1,20 @@
1
1
  module Rallio
2
+ # Represents a sign on token object as it comes from Rallio.
3
+ #
4
+ # @!attribute [rw] token
5
+ # @!attribute [rw] expires_at
6
+ # DateTime token and url will become invalid.
7
+ # @!attribute [rw] url
8
+ # Url to redirect user to for SSO with token embedded
2
9
  class SignOnToken < Base
3
10
  attribute :token, String
4
11
  attribute :expires_at, DateTime
5
12
  attribute :url, String
6
13
 
14
+ # Creates new sign on token for user_id.
15
+ #
16
+ # @param user_id [Integer]
17
+ # @return [Rallio::SignOnToken]
7
18
  def self.create(user_id:)
8
19
  response = self.post("/users/#{user_id}/sign_on_tokens", headers: app_credentials)
9
20
  new response.parsed_response['sign_on_token']
@@ -1,36 +1,69 @@
1
1
  module Rallio
2
+ # Represents a user object as it comes from Rallio.
3
+ #
4
+ # @!attribute [rw] id
5
+ # @!attribute [rw] email
6
+ # @!attribute [rw] first_name
7
+ # @!attribute [rw] last_name
2
8
  class User < Base
3
9
  attribute :id, Integer
4
10
  attribute :email, String
5
11
  attribute :first_name, String
6
12
  attribute :last_name, String
7
- attribute :accounts, Array[Account]
8
- attribute :franchisors, Array[Franchisor]
13
+ # This may not be needed anymore, API still in flux
14
+ #attribute :accounts, Array[Account]
15
+ #attribute :franchisors, Array[Franchisor]
9
16
 
10
17
  attr_writer :access_token
11
18
 
19
+ # Lists accessible users on Rallio's platform for application.
20
+ #
21
+ # @return [Array<Rallio::User>] array of users accessible to application
12
22
  def self.accessible_users
13
23
  response = self.get('/accessible_users', headers: app_credentials)
14
24
  response.parsed_response['users'].map { |u| User.new(u) }
15
25
  end
16
26
 
27
+ # Create a user on the Rallio platform.
28
+ #
29
+ # @param user [Hash] user info used to create new user
30
+ # @option user [String] :email unique email address
31
+ # @option user [String] :first_name
32
+ # @option user [String] :last_name
33
+ # @return [Rallio::User] user object that was just created
17
34
  def self.create(user:)
18
35
  response = self.post('/users', headers: app_credentials, body: { user: user })
19
36
  new response.parsed_response['user']
20
37
  end
21
38
 
39
+ # Creates new single signon for user to be redirected to.
40
+ # @see Rallio::SignOnToken
41
+ #
42
+ # @return [Rallio::SignOnToken]
22
43
  def sign_on_token
23
44
  SignOnToken.create(user_id: id)
24
45
  end
25
46
 
47
+ # Creates or returns the API access token for user.
48
+ # @see Rallio::AccessToken
49
+ #
50
+ # @return [Rallio::AccessToken]
26
51
  def access_token
27
52
  @access_token ||= AccessToken.create(user_id: id)
28
53
  end
29
54
 
55
+ # Retreives account ownerships for user.
56
+ # @see Rallio::AccountOwnership
57
+ #
58
+ # @return [Array<Rallio::AccountOwnership>] array of user's account ownerships
30
59
  def account_ownerships
31
60
  AccountOwnership.for(access_token: access_token.access_token)
32
61
  end
33
62
 
63
+ # Retreives franchisor ownerships for user.
64
+ # @see Rallio::FranchisorOwnership
65
+ #
66
+ # @return [Array<Rallio::FranchisorOwnership>] array of user's franchisor ownerships
34
67
  def franchisor_ownerships
35
68
  FranchisorOwnership.for(access_token: access_token.access_token)
36
69
  end
@@ -1,3 +1,3 @@
1
1
  module Rallio
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rallio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Guzman