Created
October 15, 2019 12:32
-
-
Save cilim/feb5d415bbd381ef7607962722238708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BranchLinkAdapter | |
BRANCH_IO_API_URL = 'https://api.branch.io/v1/url'.freeze | |
def initialize(token, desktop_url) | |
@token = token | |
@key = Rails.application.secrets.branchio_key | |
@desktop_url = desktop_url | |
end | |
def fetch | |
JSON.parse(fetch_url.body)['url'] if fetch_url.code == 200 | |
end | |
private | |
def headers | |
{ 'content_type' => 'application/json', 'accept' => 'application/json' } | |
end | |
def payload | |
# set type: 1, for one time links | |
{ | |
branch_key: @key, | |
data: { | |
token: @token, | |
'$desktop_url' => @desktop_url | |
} | |
}.to_json | |
end | |
def fetch_url | |
@fetch_url ||= RestClient.post(BRANCH_IO_API_URL, payload, headers) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment