generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52c85a5
commit 5fec0e4
Showing
2 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
class CercApiClient | ||
class << self | ||
def latest_forecasts(zone = nil) | ||
base_url = ENV.fetch("CERC_API_HOST_URL") | ||
|
||
query = { | ||
"from" => Date.today, | ||
"numdays" => 3, | ||
"zone" => zone, | ||
"key" => ENV.fetch("CERC_API_KEY") | ||
}.compact | ||
|
||
HTTParty.get("#{base_url}/getforecast/all", query: query) | ||
request("getforecast/all", query) | ||
end | ||
|
||
private | ||
|
||
def request(endpoint, query = {}) | ||
base_url = ENV.fetch("CERC_API_HOST_URL") | ||
query["key"] = ENV.fetch("CERC_API_KEY") | ||
HTTParty.get("#{base_url}/#{endpoint}", query: query) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class CercSubscriberApiClient | ||
class << self | ||
def find_subscriber(email:, phone:) | ||
# https://www.airtext.info/API/#/subscribers/get-subscriber | ||
query = { | ||
email: email, | ||
phone: phone, | ||
} | ||
|
||
request("find-subscriber", :get, query) | ||
end | ||
|
||
def get_subscriptions(subscriber_id) | ||
# https://www.airtext.info/API/#/subscriptions/get-subscriptions | ||
request("subscriptions/#{subscriber_id}", :get) | ||
end | ||
|
||
def create_subscription(zone:, mode:, ampm:, subscriber_id: nil, phone: nil, email: nil, subscriber_details: nil) | ||
# https://www.airtext.info/API/#/subscriptions/store-airtext-subscriber | ||
query = { | ||
subscriberId: subscriber_id, | ||
zone: zone, | ||
mode: mode, | ||
phone: phone, | ||
email: email, | ||
ampm: ampm, | ||
subscriberDetails: subscriber_details, | ||
} | ||
|
||
request("subscriptions", :post, query) | ||
end | ||
|
||
def delete_subscription(subscriber_id, subscription_id) | ||
# https://www.airtext.info/API/#/subscriptions/delete-subscription | ||
query = { | ||
subscriberId: subscriber_id, | ||
subscriptionId: subscription_id, | ||
} | ||
|
||
request("subscriptions", :delete, query) | ||
end | ||
|
||
private | ||
|
||
def request(endpoint, method, query = {}) | ||
base_url = 'https://london-airtext-subscriber-api-gateway-7x54d7qf.nw.gateway.dev' | ||
query["key"] = ENV.fetch("CERC_API_KEY") | ||
|
||
if method == :post | ||
HTTParty.post("#{base_url}/#{endpoint}", body: query.compact) | ||
else | ||
HTTParty.get("#{base_url}/#{endpoint}", query: query.compact) | ||
end | ||
end | ||
end | ||
end |