feathr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +41 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +98 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +13 -0
  12. data/bin/setup +8 -0
  13. data/config/solano.yml +6 -0
  14. data/feathr.gemspec +30 -0
  15. data/lib/feathr.rb +56 -0
  16. data/lib/feathr/api/account.rb +9 -0
  17. data/lib/feathr/api/accounts.rb +11 -0
  18. data/lib/feathr/api/api_token_auth.rb +14 -0
  19. data/lib/feathr/api/api_token_refresh.rb +14 -0
  20. data/lib/feathr/api/api_token_verify.rb +14 -0
  21. data/lib/feathr/api/cashout.rb +9 -0
  22. data/lib/feathr/api/cashouts.rb +20 -0
  23. data/lib/feathr/api/contractor.rb +9 -0
  24. data/lib/feathr/api/contractors.rb +11 -0
  25. data/lib/feathr/api/feathr_endpoint.rb +102 -0
  26. data/lib/feathr/api/feathr_error.rb +15 -0
  27. data/lib/feathr/api/feathr_object.rb +37 -0
  28. data/lib/feathr/api/featured_platforms.rb +11 -0
  29. data/lib/feathr/api/healthz.rb +13 -0
  30. data/lib/feathr/api/income.rb +9 -0
  31. data/lib/feathr/api/income_request.rb +9 -0
  32. data/lib/feathr/api/income_requests.rb +14 -0
  33. data/lib/feathr/api/incomes.rb +11 -0
  34. data/lib/feathr/api/invoice.rb +9 -0
  35. data/lib/feathr/api/invoices.rb +11 -0
  36. data/lib/feathr/api/manager.rb +13 -0
  37. data/lib/feathr/api/managers.rb +12 -0
  38. data/lib/feathr/api/membership.rb +27 -0
  39. data/lib/feathr/api/membership_request.rb +9 -0
  40. data/lib/feathr/api/membership_requests.rb +14 -0
  41. data/lib/feathr/api/memberships.rb +11 -0
  42. data/lib/feathr/api/paypal_service.rb +0 -0
  43. data/lib/feathr/api/platform.rb +13 -0
  44. data/lib/feathr/api/platforms.rb +11 -0
  45. data/lib/feathr/api/public_platforms.rb +11 -0
  46. data/lib/feathr/api/rebate.rb +9 -0
  47. data/lib/feathr/api/rebates.rb +11 -0
  48. data/lib/feathr/api/receiveable.rb +9 -0
  49. data/lib/feathr/api/receiveables.rb +11 -0
  50. data/lib/feathr/api/reset_password.rb +14 -0
  51. data/lib/feathr/api/user.rb +11 -0
  52. data/lib/feathr/api/users.rb +19 -0
  53. data/lib/feathr/client.rb +146 -0
  54. data/lib/feathr/config.rb +39 -0
  55. data/lib/feathr/version.rb +3 -0
  56. metadata +168 -0
File without changes
@@ -0,0 +1,13 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class Platform < Feathr::Api::FeathrObject
5
+ api_path 'platforms'
6
+
7
+ nested :contractors, :incomes, :invoices, :memberships, :membership_requests, :income_requests
8
+
9
+ # TODO: implement csv_upload?
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class Platforms < Feathr::Api::FeathrEndpoint
5
+ api_path 'platforms'
6
+ feathr_object Feathr::Api::Platform
7
+ feathr_endpoints :all, :find, :create, :destroy, :update
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class PublicPlatforms < Feathr::Api::FeathrEndpoint
5
+ api_path 'public_platforms'
6
+ feathr_object Feathr::Api::Platform
7
+ feathr_endpoints :all, :find, :create
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class Rebate < Feathr::Api::FeathrObject
5
+ api_path 'rebates'
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class Rebates < Feathr::Api::FeathrEndpoint
5
+ api_path 'rebates'
6
+ feathr_object Feathr::Api::Rebate
7
+ feathr_endpoints :all, :find
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class Receiveable < Feathr::Api::FeathrObject
5
+ api_path 'receiveables'
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class Receiveables < Feathr::Api::FeathrEndpoint
5
+ api_path 'receiveables'
6
+ feathr_object Feathr::Api::Receiveable
7
+ feathr_endpoints :all
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class ResetPassword < Feathr::Api::FeathrEndpoint
5
+ api_path 'reset-password'
6
+
7
+ def reset!(email)
8
+ query = { email: email }
9
+ client.request(method: :post, path: api_path, query: query)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class User < Feathr::Api::FeathrObject
5
+ api_path 'users'
6
+
7
+ nested :incomes, :cashouts, :accounts, :income_requests, :receiveables
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Feathr
2
+ module Api
3
+
4
+ class Users < Feathr::Api::FeathrEndpoint
5
+ api_path 'users'
6
+ feathr_object Feathr::Api::User
7
+ feathr_endpoints :all, :find, :update
8
+
9
+ def me
10
+ path = api_path + 'me'
11
+ response = client.request(method: :get, path: path) do |data|
12
+ id = data["url"][/\/(\d*)\/$/, 1]
13
+ feathr_object.new(data, id)
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,146 @@
1
+ require 'httparty'
2
+
3
+ module Feathr
4
+ class Client
5
+ include HTTParty
6
+
7
+ attr_accessor :config
8
+
9
+ def initialize(config: Feathr::Config.default)
10
+ @config = config
11
+ end
12
+
13
+ def self.default
14
+ @@default ||= Feathr::Client.new
15
+ end
16
+
17
+ def default_headers
18
+ { 'Content-Type' => 'application/json' }
19
+ end
20
+
21
+ def auth_headers
22
+ { Authorization: "Bearer #{ auth_token }" }
23
+ end
24
+
25
+ def auth_token
26
+ @auth_token ||= if defined?(Rails)
27
+ fetch_from_cache!
28
+ else
29
+ authenticate!
30
+ end
31
+ end
32
+
33
+ def authenticate!
34
+ @auth_token = api_token_auth.authenticate(
35
+ email: config.api_email,
36
+ password: config.api_password
37
+ )['token']
38
+ end
39
+
40
+ def refresh_token!
41
+ @auth_token = api_token_refresh.refresh!(auth_token)
42
+ end
43
+
44
+ def verify_token!
45
+ api_token_verify.verify(auth_token)
46
+ end
47
+
48
+ def fetch_from_cache!
49
+ Rails.cache.fetch('qwil_api_token', expires_in: 24.hours) { authenticate! }
50
+ end
51
+
52
+ def request(method: :get, path:, query: {}, headers: {})
53
+ url = [config.base_url, path].join('/')
54
+
55
+
56
+ unless path == Feathr::Api::ApiTokenAuth.new.api_path
57
+ headers = default_headers.merge(auth_headers).merge(headers)
58
+ query = query.to_json
59
+ end
60
+
61
+ response = self.class.send(
62
+ method,
63
+ url,
64
+ body: query,
65
+ headers: headers
66
+ )
67
+
68
+ if response.success? && block_given?
69
+ yield response.parsed_response
70
+ elsif response.success?
71
+ response.parsed_response
72
+ else
73
+ Feathr::Api::FeathrError.new(status: response.code, errors: response.parsed_response)
74
+ end
75
+ end
76
+
77
+ def api_token_auth
78
+ @api_token_auth ||= Feathr::Api::ApiTokenAuth.new(client: self)
79
+ end
80
+
81
+ def api_token_refresh
82
+ @api_token_refresh ||= Feathr::Api::ApiTokenRefresh.new(client: self)
83
+ end
84
+
85
+ def api_token_verify
86
+ @api_token_verify ||= Feathr::Api::ApiTokenVerify.new(client: self)
87
+ end
88
+
89
+ def reset_password
90
+ @reset_password ||= Feathr::Api::ResetPassword.new(client: self)
91
+ end
92
+
93
+ def cashouts
94
+ @cashouts ||= Feathr::Api::Cashouts.new(client: self)
95
+ end
96
+
97
+ def managers
98
+ @managers ||= Feathr::Api::Managers.new(client: self)
99
+ end
100
+
101
+ def memberships
102
+ @memberships ||= Feathr::Api::Memberships.new(client: self)
103
+ end
104
+
105
+ def platforms
106
+ @platforms ||= Feathr::Api::Platforms.new(client: self)
107
+ end
108
+
109
+ def contractors
110
+ @contractors ||= Feathr::Api::Contractors.new(client: self)
111
+ end
112
+
113
+ def incomes
114
+ @incomes ||= Feathr::Api::Incomes.new(client: self)
115
+ end
116
+
117
+ def rebates
118
+ @rebates ||= Feathr::Api::Rebates.new(client: self)
119
+ end
120
+
121
+ def receiveables
122
+ @receiveables ||= Feathr::Api::Receiveables.new(client: self)
123
+ end
124
+
125
+ def featured_platforms
126
+ @featured_platforms ||= Feathr::Api::FeaturedPlatforms.new(client: self)
127
+ end
128
+
129
+ def featured_platforms
130
+ @public_platforms ||= Feathr::Api::PublicPlatforms.new(client: self)
131
+ end
132
+
133
+ def invoices
134
+ @invoices ||= Feathr::Api::Invoices.new(client: self)
135
+ end
136
+
137
+ def memberships
138
+ @memberships ||= Feathr::Api::Memberships.new(client: self)
139
+ end
140
+
141
+ def users
142
+ @users ||= Feathr::Api::Users.new(client: self)
143
+ end
144
+
145
+ end
146
+ end
@@ -0,0 +1,39 @@
1
+ module Feathr
2
+ class Config
3
+ attr_accessor :scheme, :host, :api_key, :api_email, :api_password
4
+
5
+ DEFAULT_SCHEME = 'https'
6
+ DEFAULT_HOST = 'staging.qwil.co'
7
+ DEFAULT_API_KEY = ''
8
+
9
+ def initialize
10
+ @scheme = DEFAULT_SCHEME
11
+ @host = DEFAULT_HOST
12
+ @api_key = DEFAULT_API_KEY
13
+
14
+ yield(self) if block_given?
15
+ end
16
+
17
+ def self.default
18
+ @@default ||= Feathr::Config.new
19
+ end
20
+
21
+ def configure
22
+ yield(self) if block_given?
23
+ end
24
+
25
+ def scheme=(scheme)
26
+ # remove :// from scheme
27
+ @scheme = scheme.sub(/:\/\//, '')
28
+ end
29
+
30
+ def host=(host)
31
+ # remove http(s):// and anything after a slash
32
+ @host = host.sub(/https?:\/\//, '').split('/').first
33
+ end
34
+
35
+ def base_url
36
+ url = "#{ scheme }://#{ host }".sub(/\/+\z/, '')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Feathr
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: feathr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brad Herman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-11 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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
+ description: " Rails API for interacting with Qwil API."
84
+ email:
85
+ - brad@hired.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - config/solano.yml
102
+ - feathr.gemspec
103
+ - lib/feathr.rb
104
+ - lib/feathr/api/account.rb
105
+ - lib/feathr/api/accounts.rb
106
+ - lib/feathr/api/api_token_auth.rb
107
+ - lib/feathr/api/api_token_refresh.rb
108
+ - lib/feathr/api/api_token_verify.rb
109
+ - lib/feathr/api/cashout.rb
110
+ - lib/feathr/api/cashouts.rb
111
+ - lib/feathr/api/contractor.rb
112
+ - lib/feathr/api/contractors.rb
113
+ - lib/feathr/api/feathr_endpoint.rb
114
+ - lib/feathr/api/feathr_error.rb
115
+ - lib/feathr/api/feathr_object.rb
116
+ - lib/feathr/api/featured_platforms.rb
117
+ - lib/feathr/api/healthz.rb
118
+ - lib/feathr/api/income.rb
119
+ - lib/feathr/api/income_request.rb
120
+ - lib/feathr/api/income_requests.rb
121
+ - lib/feathr/api/incomes.rb
122
+ - lib/feathr/api/invoice.rb
123
+ - lib/feathr/api/invoices.rb
124
+ - lib/feathr/api/manager.rb
125
+ - lib/feathr/api/managers.rb
126
+ - lib/feathr/api/membership.rb
127
+ - lib/feathr/api/membership_request.rb
128
+ - lib/feathr/api/membership_requests.rb
129
+ - lib/feathr/api/memberships.rb
130
+ - lib/feathr/api/paypal_service.rb
131
+ - lib/feathr/api/platform.rb
132
+ - lib/feathr/api/platforms.rb
133
+ - lib/feathr/api/public_platforms.rb
134
+ - lib/feathr/api/rebate.rb
135
+ - lib/feathr/api/rebates.rb
136
+ - lib/feathr/api/receiveable.rb
137
+ - lib/feathr/api/receiveables.rb
138
+ - lib/feathr/api/reset_password.rb
139
+ - lib/feathr/api/user.rb
140
+ - lib/feathr/api/users.rb
141
+ - lib/feathr/client.rb
142
+ - lib/feathr/config.rb
143
+ - lib/feathr/version.rb
144
+ homepage: https://github.com/hired/feathr
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.5.2
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Rails API for interacting with Qwil API.
168
+ test_files: []