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 method to support requests to Ads API. #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions lib/extwitter/api/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ defmodule ExTwitter.API.Base do
do_request(method, upload_url(path), params)
end

@doc """
Send request to the ads-api.twitter.com server.
"""
def ads_request(method, path, params \\ []) do
do_request(method, ads_url(path), params)
end

defp do_request(method, url, params) do
oauth = ExTwitter.Config.get_tuples |> verify_params
consumer = {oauth[:consumer_key], oauth[:consumer_secret], :hmac_sha1}
Expand Down Expand Up @@ -51,6 +58,10 @@ defmodule ExTwitter.API.Base do
"https://upload.twitter.com/#{path}" |> to_char_list
end

defp ads_url(path) do
"https://ads-api.twitter.com/#{path}" |> to_char_list
end

def parse_result(result) do
{:ok, {_response, header, body}} = result
verify_response(ExTwitter.JSON.decode!(body), header)
Expand Down