billfixers-partner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a1ff53d13f69d7ec9d71b000f036386f043330b2435997a19ca55f2264edd94
4
+ data.tar.gz: 467b7632fe1922c403e4224bc565e60419c7603b19e9c6cc552bca2ac7fdb2a0
5
+ SHA512:
6
+ metadata.gz: 11b12bc31833fc8d77a2df1543cb4847df8681a727f92d4984d8311023d321f72afa78aeb515314683279d4b3a2147db24772cf1cc808947a0a7b1db65feb70a
7
+ data.tar.gz: 0bf8245133fbda1ab82122bcd72b571e3edd52cb5593faead86c92b35cbcaeb5b73a85c4dccd8562c439e460cc520f03d7d5423832d953a305a85c0d6f0b1c73
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in billfixers-partner.gemspec
6
+ gemspec
7
+
8
+ gem 'activesupport'
9
+ gem 'graphlient'
10
+ gem 'minitest', '~> 5.0'
11
+ gem 'rake', '~> 12.0'
12
+ gem 'webmock'
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ billfixers-partner (0.1.0)
5
+ activesupport
6
+ graphlient
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.0.3.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
17
+ addressable (2.7.0)
18
+ public_suffix (>= 2.0.2, < 5.0)
19
+ concurrent-ruby (1.1.7)
20
+ crack (0.4.3)
21
+ safe_yaml (~> 1.0.0)
22
+ faraday (1.0.1)
23
+ multipart-post (>= 1.2, < 3)
24
+ faraday_middleware (1.0.0)
25
+ faraday (~> 1.0)
26
+ graphlient (0.4.0)
27
+ faraday (>= 1.0)
28
+ faraday_middleware
29
+ graphql-client
30
+ graphql (1.11.3)
31
+ graphql-client (0.16.0)
32
+ activesupport (>= 3.0)
33
+ graphql (~> 1.8)
34
+ hashdiff (1.0.1)
35
+ i18n (1.8.5)
36
+ concurrent-ruby (~> 1.0)
37
+ minitest (5.14.1)
38
+ multipart-post (2.1.1)
39
+ public_suffix (4.0.5)
40
+ rake (12.3.3)
41
+ safe_yaml (1.0.5)
42
+ thread_safe (0.3.6)
43
+ tzinfo (1.2.7)
44
+ thread_safe (~> 0.1)
45
+ webmock (3.8.3)
46
+ addressable (>= 2.3.6)
47
+ crack (>= 0.3.2)
48
+ hashdiff (>= 0.4.0, < 2.0.0)
49
+ zeitwerk (2.4.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ activesupport
56
+ billfixers-partner!
57
+ graphlient
58
+ minitest (~> 5.0)
59
+ rake (~> 12.0)
60
+ webmock
61
+
62
+ BUNDLED WITH
63
+ 2.1.4
@@ -0,0 +1,36 @@
1
+ # Billfixers::Partner
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/billfixers/partner`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'billfixers-partner'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install billfixers-partner
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/billfixers-partner.
36
+
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ t.warning = false
11
+ end
12
+
13
+ task default: :test
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/billfixers/partner/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'billfixers-partner'
7
+ spec.version = Billfixers::Partner::VERSION
8
+ spec.authors = ['BillFixers']
9
+ spec.email = ['help@billfixers.com']
10
+
11
+ spec.summary = 'Billfixers Partner API'
12
+ spec.description = 'Billfixers Partner API'
13
+ spec.homepage = 'https://billfixers.com'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_dependency 'activesupport'
32
+ spec.add_dependency 'graphlient'
33
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "billfixers/partner"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'billfixers/partner/version'
4
+ require 'billfixers/partner/client'
5
+ require 'billfixers/partner/gql'
6
+
7
+ module Billfixers
8
+ module Partner
9
+ class Error < StandardError; end
10
+ end
11
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/all'
4
+ require 'graphlient'
5
+
6
+ module Billfixers
7
+ module Partner
8
+ class Client
9
+ def initialize(email:, token:, test_mode: false)
10
+ endpoint = test_mode ? 'https://billfixers-staging.herokuapp.com/partner/graphql' : 'https://billfixers.herokuapp.com/partner/graphql'
11
+
12
+ @gql = Graphlient::Client.new(endpoint,
13
+ schema_path: './partner_schema.json',
14
+ headers: {
15
+ "X-PartnerUser-Email": email,
16
+ "X-PartnerUser-Token": token
17
+ })
18
+ end
19
+
20
+ def list_providers
21
+ response = @gql.query(LIST_PROVIDERS_QUERY)
22
+
23
+ response.data.list_providers
24
+ end
25
+
26
+ def list_customers(limit: 25, offset: 0)
27
+ response = @gql.query(LIST_CUSTOMERS_QUERY, {
28
+ limit: limit,
29
+ offset: offset
30
+ })
31
+
32
+ result = response.data.list_customers
33
+
34
+ [result.total_count, result.nodes]
35
+ end
36
+
37
+ def list_bills(limit: 25, offset: 0, customer_id: nil)
38
+ response = @gql.query(LIST_BILLS_QUERY, {
39
+ limit: limit,
40
+ offset: offset,
41
+ customer_id: customer_id
42
+ })
43
+
44
+ result = response.data.list_bills
45
+
46
+ [result.total_count, result.nodes]
47
+ end
48
+
49
+ def list_offers(limit: 25, offset: 0, customer_id: nil, bill_id: nil)
50
+ response = @gql.query(LIST_OFFERS_QUERY, {
51
+ limit: limit,
52
+ offset: offset,
53
+ customer_id: customer_id,
54
+ bill_id: bill_id
55
+ })
56
+
57
+ result = response.data.list_offers
58
+
59
+ [result.total_count, result.nodes]
60
+ end
61
+
62
+ def find_customer(customer_id)
63
+ response = @gql.query(FIND_CUSTOMER_QUERY, { id: customer_id })
64
+ response.data.find_customer
65
+ end
66
+
67
+ def find_bill(bill_id)
68
+ response = @gql.query(FIND_BILL_QUERY, { id: bill_id })
69
+ response.data.find_bill
70
+ end
71
+
72
+ def create_customer(params)
73
+ response = @gql.query(CREATE_CUSTOMER_MUTATION, {
74
+ customer: camelize(params)
75
+ })
76
+
77
+ result = response.data.create_customer
78
+ raise Error, result.errors.join(' ') unless result.success
79
+
80
+ result.customer
81
+ end
82
+
83
+ def create_bill(params)
84
+ response = @gql.query(CREATE_BILL_MUTATION, {
85
+ bill: camelize(params)
86
+ })
87
+
88
+ result = response.data.create_bill
89
+ raise Error, result.errors.join(' ') unless result.success
90
+
91
+ result.bill
92
+ end
93
+
94
+ def cancel_bill(bill_id)
95
+ response = @gql.query(CANCEL_BILL_MUTATION, { id: bill_id })
96
+
97
+ response.data.cancel_bill.success
98
+ end
99
+
100
+ def accept_offer(offer_id)
101
+ response = @gql.query(ACCEPT_OFFER_MUTATION, { id: offer_id })
102
+
103
+ result = response.data.accept_offer
104
+ raise Error, result.errors.join(' ') unless result.success
105
+
106
+ result.offer
107
+ end
108
+
109
+ def reject_offer(offer_id)
110
+ response = @gql.query(REJECT_OFFER_MUTATION, { id: offer_id })
111
+
112
+ result = response.data.reject_offer
113
+ raise Error, result.errors.join(' ') unless result.success
114
+
115
+ result.offer
116
+ end
117
+
118
+ private
119
+
120
+ def camelize(hsh)
121
+ hsh.deep_transform_keys { |key| key.to_s.camelize(:lower) }
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,207 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Billfixers
4
+ module Partner
5
+ PROVIDER_FRAGMENT = %(
6
+ id
7
+ name
8
+ services
9
+ )
10
+
11
+ CUSTOMER_FRAGMENT = %(
12
+ id
13
+ email
14
+ name
15
+ firstName
16
+ lastName
17
+ phoneNumber
18
+ avatarUrl
19
+ b2b
20
+ addressLine1
21
+ addressLine2
22
+ addressCity
23
+ addressState
24
+ addressPostalCode
25
+ addressCountryCode
26
+ createdAt
27
+ updatedAt
28
+ )
29
+
30
+ BILL_ITEM_FRAGMENT = %(
31
+ name
32
+ prePrice
33
+ postPrice
34
+ duration
35
+ savings
36
+ savingsStartOn
37
+ savingsEndOn
38
+ underContract
39
+ createdAt
40
+ updatedAt
41
+ )
42
+
43
+ BILL_FRAGMENT = %(
44
+ id
45
+ status
46
+ title
47
+ providerId
48
+ totalSavings
49
+ createdAt
50
+ updatedAt
51
+
52
+ items {
53
+ #{BILL_ITEM_FRAGMENT}
54
+ }
55
+ customer {
56
+ #{CUSTOMER_FRAGMENT}
57
+ }
58
+ provider {
59
+ #{PROVIDER_FRAGMENT}
60
+ }
61
+ )
62
+
63
+ OFFER_FRAGMENT = %(
64
+ id
65
+ status
66
+ content
67
+ contentHtml
68
+ createdAt
69
+ updatedAt
70
+ acceptedAt
71
+ rejectedAt
72
+
73
+ customer {
74
+ #{CUSTOMER_FRAGMENT}
75
+ }
76
+
77
+ bill {
78
+ #{BILL_FRAGMENT}
79
+ }
80
+ )
81
+
82
+ LIST_PROVIDERS_QUERY = %(
83
+ query {
84
+ ListProviders {
85
+ #{PROVIDER_FRAGMENT}
86
+ }
87
+ }
88
+ )
89
+
90
+ LIST_CUSTOMERS_QUERY = %(
91
+ query($limit: Int, $offset: Int) {
92
+ ListCustomers(
93
+ limit: $limit,
94
+ offset: $offset
95
+ ) {
96
+ totalCount
97
+ nodes {
98
+ #{CUSTOMER_FRAGMENT}
99
+ }
100
+ }
101
+ }
102
+ )
103
+
104
+ LIST_BILLS_QUERY = %(
105
+ query($limit: Int, $offset: Int, $customer_id: ID) {
106
+ ListBills(
107
+ limit: $limit,
108
+ offset: $offset,
109
+ customerId: $customer_id
110
+ ) {
111
+ totalCount
112
+ nodes {
113
+ #{BILL_FRAGMENT}
114
+ }
115
+ }
116
+ }
117
+ )
118
+
119
+ LIST_OFFERS_QUERY = %(
120
+ query($limit: Int, $offset: Int, $customer_id: ID, $bill_id: ID) {
121
+ ListOffers(
122
+ limit: $limit,
123
+ offset: $offset,
124
+ customerId: $customer_id,
125
+ billId: $bill_id
126
+ ) {
127
+ totalCount
128
+ nodes {
129
+ #{OFFER_FRAGMENT}
130
+ }
131
+ }
132
+ }
133
+ )
134
+
135
+ FIND_CUSTOMER_QUERY = %(
136
+ query($id: ID!) {
137
+ FindCustomer(id: $id) {
138
+ #{CUSTOMER_FRAGMENT}
139
+ }
140
+ }
141
+ )
142
+
143
+ FIND_BILL_QUERY = %(
144
+ query($id: ID!) {
145
+ FindBill(id: $id) {
146
+ #{BILL_FRAGMENT}
147
+ }
148
+ }
149
+ )
150
+
151
+ CREATE_CUSTOMER_MUTATION = %(
152
+ mutation($customer: CustomerAttributes!) {
153
+ CreateCustomer(input: { customer: $customer }) {
154
+ success
155
+ errors
156
+ customer {
157
+ #{CUSTOMER_FRAGMENT}
158
+ }
159
+ }
160
+ }
161
+ )
162
+
163
+ CREATE_BILL_MUTATION = %(
164
+ mutation($bill: BillAttributes!) {
165
+ CreateBill(input: { bill: $bill }) {
166
+ success
167
+ errors
168
+ bill {
169
+ #{BILL_FRAGMENT}
170
+ }
171
+ }
172
+ }
173
+ )
174
+
175
+ CANCEL_BILL_MUTATION = %(
176
+ mutation($id: ID!) {
177
+ CancelBill(input: { id: $id }) {
178
+ success
179
+ }
180
+ }
181
+ )
182
+
183
+ ACCEPT_OFFER_MUTATION = %(
184
+ mutation($id: ID!) {
185
+ AcceptOffer(input: { id: $id }) {
186
+ success
187
+ errors
188
+ offer {
189
+ #{OFFER_FRAGMENT}
190
+ }
191
+ }
192
+ }
193
+ )
194
+
195
+ REJECT_OFFER_MUTATION = %(
196
+ mutation($id: ID!) {
197
+ RejectOffer(input: { id: $id }) {
198
+ success
199
+ errors
200
+ offer {
201
+ #{OFFER_FRAGMENT}
202
+ }
203
+ }
204
+ }
205
+ )
206
+ end
207
+ end