Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for region api endpoint #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/customerio/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def execute(method, path, body = nil, headers = {})

def request_class(method)
case method
when :get
Net::HTTP::Get
when :post
Net::HTTP::Post
when :put
Expand Down
10 changes: 10 additions & 0 deletions lib/customerio/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ def initialize(site_id, api_key, options = {})
@client = Customerio::BaseClient.new({ site_id: site_id, api_key: api_key }, options)
end

def region
response = @client.request(:get, "/api/v1/accounts/region")
case response
when Net::HTTPSuccess
JSON.parse(response.body)
else
raise InvalidResponse.new(response.code, response.body)
end
end

def identify(attributes)
create_or_update(attributes)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,20 @@ def json(data)
lambda { client.delete_device(5, nil) }.should raise_error(Customerio::Client::ParamError)
end
end

describe "#region" do
it "sends a GET request to the customer.io's region API" do
stub_request(:get, api_uri('/api/v1/accounts/region')).
to_return(status: 200, body: { region: "eu" }.to_json, headers: {})

expect(client.region).to eq("region" => "eu")
end

it "throws an error when customer_id is missing" do
stub_request(:put, /track.customer.io/)
.to_return(status: 200, body: "", headers: {})

lambda { client.suppress(" ") }.should raise_error(Customerio::Client::ParamError, "customer_id must be a non-empty string")
end
end
end