Class: Billfixers::Partner::Client
- Inherits:
-
Object
- Object
- Billfixers::Partner::Client
- Defined in:
- lib/billfixers/partner/client.rb
Instance Method Summary collapse
- #accept_offer(offer_id) ⇒ Object
- #calculate_savings_estimate(provider_id, current_monthly_payment) ⇒ Object
- #create_bill(customer_id, provider_id, params) ⇒ Object
- #create_customer(params) ⇒ Object
- #find_bill(bill_id) ⇒ Object
- #find_customer(customer_id) ⇒ Object
- #find_information_request(information_request_id) ⇒ Object
- #find_offer(offer_id) ⇒ Object
-
#initialize(api_key:) ⇒ Client
constructor
A new instance of Client.
- #list_bills(limit: 25, offset: 0, customer_id: nil) ⇒ Object
- #list_customers(limit: 25, offset: 0) ⇒ Object
- #list_information_requests(limit: 25, offset: 0, customer_id: nil) ⇒ Object
- #list_offers(limit: 25, offset: 0, customer_id: nil, bill_id: nil, status: nil) ⇒ Object
- #list_providers ⇒ Object
- #provide_documentless_info(bill_id, documentless_info) ⇒ Object
- #reject_offer(offer_id) ⇒ Object
- #renegotiate_bill(bill_id) ⇒ Object
- #respond_to_information_request(information_request_id, params) ⇒ Object
- #stop_negotiating(bill_id) ⇒ Object
- #update_bill(bill_id, params) ⇒ Object
Constructor Details
#initialize(api_key:) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/billfixers/partner/client.rb', line 9 def initialize(api_key:) test_mode = api_key.start_with?('test_') endpoint = test_mode ? 'https://billfixers-partner-sandbox.herokuapp.com/partner/graphql' : 'https://billfixers.herokuapp.com/partner/graphql' @gql = Graphlient::Client.new(endpoint, schema_path: File.join(File.dirname(__FILE__), '../../../partner_schema.json'), headers: { "X-Partner-ApiKey": api_key }) end |
Instance Method Details
#accept_offer(offer_id) ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/billfixers/partner/client.rb', line 148 def accept_offer(offer_id) response = @gql.query(ACCEPT_OFFER_MUTATION, { id: offer_id }) result = response.data.accept_offer raise Error, result.errors.join(' ') unless result.success result.offer end |
#calculate_savings_estimate(provider_id, current_monthly_payment) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/billfixers/partner/client.rb', line 182 def calculate_savings_estimate(provider_id, current_monthly_payment) response = @gql.query( CALCULATE_SAVINGS_ESTIMATE, { provider_id: provider_id, current_monthly_amount: current_monthly_payment } ) response.data.calculate_savings_estimate end |
#create_bill(customer_id, provider_id, params) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/billfixers/partner/client.rb', line 107 def create_bill(customer_id, provider_id, params) response = @gql.query(CREATE_BILL_MUTATION, { customer_id: customer_id, provider_id: provider_id, bill: camelize(params) }) result = response.data.create_bill raise Error, result.errors.join(' ') unless result.success result.bill end |
#create_customer(params) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/billfixers/partner/client.rb', line 96 def create_customer(params) response = @gql.query(CREATE_CUSTOMER_MUTATION, { customer: camelize(params) }) result = response.data.create_customer raise Error, result.errors.join(' ') unless result.success result.customer end |
#find_bill(bill_id) ⇒ Object
81 82 83 84 |
# File 'lib/billfixers/partner/client.rb', line 81 def find_bill(bill_id) response = @gql.query(FIND_BILL_QUERY, { id: bill_id }) response.data.find_bill end |
#find_customer(customer_id) ⇒ Object
76 77 78 79 |
# File 'lib/billfixers/partner/client.rb', line 76 def find_customer(customer_id) response = @gql.query(FIND_CUSTOMER_QUERY, { id: customer_id }) response.data.find_customer end |
#find_information_request(information_request_id) ⇒ Object
91 92 93 94 |
# File 'lib/billfixers/partner/client.rb', line 91 def find_information_request(information_request_id) response = @gql.query(FIND_INFORMATION_REQUEST_QUERY, { id: information_request_id }) response.data.find_information_request end |
#find_offer(offer_id) ⇒ Object
86 87 88 89 |
# File 'lib/billfixers/partner/client.rb', line 86 def find_offer(offer_id) response = @gql.query(FIND_OFFER_QUERY, { id: offer_id }) response.data.find_offer end |
#list_bills(limit: 25, offset: 0, customer_id: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/billfixers/partner/client.rb', line 38 def list_bills(limit: 25, offset: 0, customer_id: nil) response = @gql.query(LIST_BILLS_QUERY, { limit: limit, offset: offset, customer_id: customer_id }) result = response.data.list_bills [result.total_count, result.nodes] end |
#list_customers(limit: 25, offset: 0) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/billfixers/partner/client.rb', line 27 def list_customers(limit: 25, offset: 0) response = @gql.query(LIST_CUSTOMERS_QUERY, { limit: limit, offset: offset }) result = response.data.list_customers [result.total_count, result.nodes] end |
#list_information_requests(limit: 25, offset: 0, customer_id: nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/billfixers/partner/client.rb', line 64 def list_information_requests(limit: 25, offset: 0, customer_id: nil) response = @gql.query(LIST_INFORMATION_REQUESTS_QUERY, { limit: limit, offset: offset, customer_id: customer_id }) result = response.data.list_information_requests [result.total_count, result.nodes] end |
#list_offers(limit: 25, offset: 0, customer_id: nil, bill_id: nil, status: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/billfixers/partner/client.rb', line 50 def list_offers(limit: 25, offset: 0, customer_id: nil, bill_id: nil, status: nil) response = @gql.query(LIST_OFFERS_QUERY, { limit: limit, offset: offset, customer_id: customer_id, bill_id: bill_id, status: status }) result = response.data.list_offers [result.total_count, result.nodes] end |
#list_providers ⇒ Object
21 22 23 24 25 |
# File 'lib/billfixers/partner/client.rb', line 21 def list_providers response = @gql.query(LIST_PROVIDERS_QUERY) response.data.list_providers end |
#provide_documentless_info(bill_id, documentless_info) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/billfixers/partner/client.rb', line 194 def provide_documentless_info(bill_id, documentless_info) response = @gql.query( PROVIDE_DOCUMENTLESS_INFO_MUTATION, { bill_id: bill_id, documentless_info: documentless_info } ) response.data.provide_documentless_info end |
#reject_offer(offer_id) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/billfixers/partner/client.rb', line 157 def reject_offer(offer_id) response = @gql.query(REJECT_OFFER_MUTATION, { id: offer_id }) result = response.data.reject_offer # binding.pry raise Error, result.errors.join(' ') unless result.success result.offer end |
#renegotiate_bill(bill_id) ⇒ Object
132 133 134 135 136 |
# File 'lib/billfixers/partner/client.rb', line 132 def renegotiate_bill(bill_id) response = @gql.query(RENEGOTIATE_BILL_MUTATION, { id: bill_id }) response.data.renegotiate_bill end |
#respond_to_information_request(information_request_id, params) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/billfixers/partner/client.rb', line 167 def respond_to_information_request(information_request_id, params) response = @gql.query( RESPOND_TO_INFORMATION_REQUEST, { id: information_request_id, information_request: camelize(params) } ) result = response.data.respond_to_information_request raise Error, result.errors.join(' ') unless result.success result.information_request end |
#stop_negotiating(bill_id) ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/billfixers/partner/client.rb', line 138 def stop_negotiating(bill_id) response = @gql.query(STOP_NEGOTIATING_MUTATION, { id: bill_id }) result = response.data.stop_negotiating raise Error, result.errors.join(' ') unless result.success result end |
#update_bill(bill_id, params) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/billfixers/partner/client.rb', line 120 def update_bill(bill_id, params) response = @gql.query(UPDATE_BILL_MUTATION, { bill_id: bill_id, bill: camelize(params) }) result = response.data.update_bill raise Error, result.errors.join(' ') unless result.success result.bill end |