Class: Webhookdb::Oauth::IncreaseProvider
- Includes:
- Appydays::Loggable
- Defined in:
- lib/webhookdb/oauth/increase_provider.rb
Class Method Summary collapse
Instance Method Summary collapse
- #app_name ⇒ Object
- #authorization_url(state:) ⇒ Object
- #build_marketplace_integrations(organization:, tokens:) ⇒ Object
- #exchange_authorization_code(code:) ⇒ Object
- #key ⇒ Object
-
#supports_webhooks? ⇒ Boolean
Increase POSTs all Oauth app webhooks to the same place.
Class Method Details
.disconnect_oauth(connection_id) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/webhookdb/oauth/increase_provider.rb', line 72 def self.disconnect_oauth(connection_id) # It may have already been deleted, make this idempotent. # See above for why we store the connection id directly. Webhookdb::ServiceIntegration.where(service_name: "increase_app_v1"). with_encrypted_value(:webhookdb_api_key, connection_id). all. each(&:destroy_self_and_all_dependents) end |
Instance Method Details
#app_name ⇒ Object
9 10 |
# File 'lib/webhookdb/oauth/increase_provider.rb', line 9 def app_name = "Increase" # Increase POSTs all Oauth app webhooks to the same place |
#authorization_url(state:) ⇒ Object
13 14 15 |
# File 'lib/webhookdb/oauth/increase_provider.rb', line 13 def (state:) return "https://increase.com/oauth/authorization?client_id=#{Webhookdb::Increase.oauth_client_id}&state=#{state}&scope=read_only" end |
#build_marketplace_integrations(organization:, tokens:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/webhookdb/oauth/increase_provider.rb', line 33 def build_marketplace_integrations(organization:, tokens:, **) group_resp = Webhookdb::Http.get( "https://api.increase.com/groups/current", headers: {"Authorization" => "Bearer #{tokens.access_token}"}, logger: self.logger, timeout: Webhookdb::Increase.http_timeout, ) group_id = group_resp.parsed_response.fetch("id") # We need to store the Oauth Connection ID for the group, so when there is an oauth disconnect, # we know which replicator to destroy. # # The deactivation comes through as an event on the Platform account, # and does not tell us the Group ID. And we cannot fetch the OAuth Connection # on the Platform account, since once a Connection is deactivated, # the Increase API will not return it. # # This seems like a bug, and has been reported to Increase. # If their /oauth_connections/:id endpoint starts working for 'inactive' connections, # this code can be removed, and we can look up the group ID when we handle the deactivate webhook. oauth_conns_resp = Webhookdb::Http.get( "https://api.increase.com/oauth_connections", headers: {"Authorization" => "Bearer #{Webhookdb::Increase.api_key}"}, logger: self.logger, timeout: Webhookdb::Increase.http_timeout, ) group_conn = oauth_conns_resp.parsed_response["data"].find { |c| c.fetch("group_id") == group_id } raise Webhookdb::InvariantViolation, "no OAuth Connection for Group #{group_id}/Org #{organization.key}" if group_conn.nil? root_sint = Webhookdb::ServiceIntegration.create_disambiguated( "increase_app_v1", organization:, api_url: group_id, backfill_key: tokens.access_token, webhookdb_api_key: group_conn.fetch("id"), ) root_sint.replicator.build_dependents return root_sint end |
#exchange_authorization_code(code:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/webhookdb/oauth/increase_provider.rb', line 17 def (code:) token_resp = Webhookdb::Http.post( "https://api.increase.com/oauth/tokens", { "client_id" => Webhookdb::Increase.oauth_client_id, "client_secret" => Webhookdb::Increase.oauth_client_secret, "code" => code, grant_type: "authorization_code", }, headers: {"Authorization" => "Bearer #{Webhookdb::Increase.api_key}"}, logger: self.logger, timeout: Webhookdb::Increase.http_timeout, ) return Webhookdb::Oauth::Tokens.new(access_token: token_resp.parsed_response["access_token"]) end |
#key ⇒ Object
8 |
# File 'lib/webhookdb/oauth/increase_provider.rb', line 8 def key = "increase" |
#supports_webhooks? ⇒ Boolean
Increase POSTs all Oauth app webhooks to the same place
11 |
# File 'lib/webhookdb/oauth/increase_provider.rb', line 11 def supports_webhooks? = true |