Skip to content

Commit

Permalink
New API
Browse files Browse the repository at this point in the history
  • Loading branch information
jdudley1123 committed Nov 20, 2024
1 parent 52c85a5 commit 5fec0e4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/models/cerc_api_client.rb
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
56 changes: 56 additions & 0 deletions app/models/cerc_subscriber_api_client.rb
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

0 comments on commit 5fec0e4

Please sign in to comment.