Class: BranchIO::Client

Inherits:
Object
  • Object
show all
Includes:
Links, HTTParty
Defined in:
lib/branch_io/client.rb,
lib/branch_io/client/links.rb,
lib/branch_io/client/response.rb

Defined Under Namespace

Modules: Links Classes: BulkUrlsResponse, ErrorApiCallFailed, ErrorMissingBranchKey, ErrorResponse, LinkPropertiesResponse, Response, UrlResponse

Constant Summary

Constants included from Links

Links::LINK_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Links

#link, #link!, #link_info, #link_info!, #links, #links!, #update_link, #update_link!

Constructor Details

#initialize(branch_key = ENV["BRANCH_KEY"], branch_secret = ENV["BRANCH_SECRET"]) ⇒ Client

Returns a new instance of Client.



21
22
23
24
25
26
27
28
# File 'lib/branch_io/client.rb', line 21

def initialize(branch_key=ENV["BRANCH_KEY"], branch_secret=ENV["BRANCH_SECRET"])
  @branch_key = branch_key
  @branch_secret = branch_secret

  unless branch_key
    raise ErrorMissingBranchKey.new("No Branch Key found: please provided one such key to BranchIO::Client#initialize or by setting the BRANCH_KEY environment variable")
  end
end

Instance Attribute Details

#branch_keyObject (readonly)

Basic Api client



20
21
22
# File 'lib/branch_io/client.rb', line 20

def branch_key
  @branch_key
end

#branch_secretObject (readonly)

Basic Api client



20
21
22
# File 'lib/branch_io/client.rb', line 20

def branch_secret
  @branch_secret
end

Instance Method Details

#get(url) ⇒ Object



30
31
32
# File 'lib/branch_io/client.rb', line 30

def get(url)
  self.class.get(url, headers: default_headers)
end

#post(url, data = {}) ⇒ Object



34
35
36
37
# File 'lib/branch_io/client.rb', line 34

def post(url, data={})
  body = data.to_json
  self.class.post(url, body: body, headers: default_headers)
end

#put(url, data = {}) ⇒ Object



39
40
41
42
# File 'lib/branch_io/client.rb', line 39

def put(url, data={})
  body = data.to_json
  self.class.put(url, body: body, headers: default_headers)
end