-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2004 from brave-intl/staging
Release 2019-06-26
- Loading branch information
Showing
8 changed files
with
157 additions
and
11 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
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
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
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
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
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,25 @@ | ||
module Promo | ||
class Client < BaseApiClient | ||
def initialize(connection = nil, options = {}) | ||
@connection = connection | ||
end | ||
|
||
def owner_state | ||
Promo::Models::OwnerState.new(connection) | ||
end | ||
|
||
private | ||
|
||
def perform_offline | ||
true | ||
end | ||
|
||
def api_base_uri | ||
Rails.application.secrets[:api_promo_base_uri] | ||
end | ||
|
||
def api_authorization_header | ||
"Bearer #{Rails.application.secrets[:api_promo_key]}" | ||
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,59 @@ | ||
require 'addressable/template' | ||
require 'json' | ||
|
||
module Promo | ||
module Models | ||
class OwnerState < Client | ||
# For more information about how these URI templates are structured read the explaination in the RFC | ||
# https://www.rfc-editor.org/rfc/rfc6570.txt | ||
PATH = Addressable::Template.new("/api/2/promo/owners/{id}/states{/state}") | ||
|
||
class State | ||
SUSPEND = "suspend".freeze | ||
NO_UGP = "no_ugp".freeze | ||
end | ||
|
||
def initialize(connection, params = {}) | ||
super(connection, params) | ||
end | ||
|
||
# Finds the current state of the owner on the promo server | ||
# | ||
# @param [String] id The publisher id to find on the promo server. | ||
# | ||
# @return [array] of owner states | ||
def find(id:) | ||
response = get(PATH.expand(id: id)) | ||
|
||
JSON.parse(response.body) | ||
end | ||
|
||
# Creates a new state for the specified owner | ||
# | ||
# @param [String] id The publisher id | ||
# @state [Promo::Models::OwnerState::State] state The state to put the owner into. | ||
# | ||
# @return [true] if create was a success | ||
def create(id:, state:) | ||
response = put(PATH.expand(id: id, state: state)) | ||
|
||
# response.body returns an array of owner states | ||
# ["no_ugp", "suspend"] | ||
JSON.parse(response.body).include? state | ||
end | ||
|
||
# Removes the state for the specified owner | ||
# | ||
# @param [String] id The publisher id | ||
# @state [Promo::Models::OwnerState::State] state The state to remove from the owner. | ||
# | ||
# @return [true] if destroy was a success | ||
def destroy(id:, state:) | ||
response = delete(PATH.expand(id: id, state: state)) | ||
|
||
# response.body returns an array of owner states | ||
JSON.parse(response.body).exclude? state | ||
end | ||
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