Skip to content

Commit

Permalink
Merge pull request #2004 from brave-intl/staging
Browse files Browse the repository at this point in the history
Release 2019-06-26
  • Loading branch information
Cory McDonald authored Jun 26, 2019
2 parents 8053dfc + 18e422f commit 2dbd1c0
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ gem "active_model_serializers", "~> 0.10.0"
# ActiveRecord Session store for server side storage of session data
gem 'activerecord-session_store'

# Allowing for URI templates, for HTTP clients
gem 'addressable', '~> 2.6'

# Pagination
gem "api-pagination"

Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ DEPENDENCIES
active_model_serializers (~> 0.10.0)
activejob-traffic_control
activerecord-session_store
addressable (~> 2.6)
api-pagination
attr_encrypted (~> 3.1.0)
autometal-piwik!
Expand Down
1 change: 1 addition & 0 deletions app/jobs/publisher_removal_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def perform(publisher_id:)
publisher = Publisher.find_by(id: publisher_id)
return if publisher.suspended?
publisher.status_updates.create(status: PublisherStatusUpdate::DELETED)
publisher.reload
ActiveRecord::Base.transaction do
publisher.update(email: nil)
publisher.update(pending_email: nil)
Expand Down
3 changes: 2 additions & 1 deletion app/models/json_builders/channels_json_builder_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def site_banner_details(channel)
end
end

# (Albert Wang): Note: Ordering is different from v1
def append_excluded
@excluded_channel_ids.each do |excluded_channel_id|
@channels.push([excluded_channel_id, false, true, {}, nil])
@channels.push([excluded_channel_id, false, true, "", {}])
end
end
end
58 changes: 58 additions & 0 deletions app/services/base_api_client.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,68 @@
class BaseApiClient < BaseService
# Make a GET request.
#
# path - [String] the path relative to the endpoint
# options - [Hash] the parameters to supply
#
# returns the response
def get(path, options = {})
request(:get, path, params: options)
end

# Make a POST request.
#
# path - [String] the path relative to the endpoint
# options - [Hash] the parameters to supply
#
# returns - [Response] the response
def post(path, options = {})
request(:post, path, form: options)
end

# Make a PUT request.
#
# path - [String] the path relative to the endpoint
# options - [Hash] the parameters to supply
#
# returns [Response] the response
def put(path, options = {})
request(:put, path, form: options)
end

# Make a PATCH request.
#
# path - [String] the path relative to the endpoint
# options - [Hash] the parameters to supply
#
# returns [Response] the response
def patch(path, options = {})
request(:patch, path, form: options)
end

# Make a DELETE request.
# path - [String] the path relative to the endpoint
# options - [Hash] the parameters to supply
# returns [Response] the response
def delete(path, options = {})
request(:delete, path, form: options)
end

private

def api_base_uri
raise "specify me"
end

def request(method, path, payload = {})
@connection.send(method) do |req|
req.url [api_base_uri, path].join('')
req.headers["Authorization"] = api_authorization_header
req.headers['Content-Type'] = 'application/json'
req.body = payload.to_json if method.to_sym.eql?(:post)
req.params = payload if method.to_sym.eql?(:get)
end
end

def connection
@connection ||= begin
require "faraday"
Expand Down
25 changes: 25 additions & 0 deletions app/services/promo/client.rb
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
59 changes: 59 additions & 0 deletions app/services/promo/models/owner_state.rb
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
18 changes: 8 additions & 10 deletions app/views/publishers/_choose_channel_type.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@
= t "publishers.choose_new_channel_type.twitch.description"

= link_to(publisher_register_twitter_channel_omniauth_authorize_path, method: :post, class: 'card block-link--card', :"data-piwik-action" => "AddTwitterChannelClicked", :"data-piwik-name" => "Clicked", :"data-piwik-value" => "AddChannelFlow") do
.new-tag
.card-body
.icon-and-text--icon
= image_tag "choose-channel/twitter.svg", class: "choose-channel--icon"
.icon-and-text--text
h6= t "publishers.choose_new_channel_type.twitter.heading"
= t "publishers.choose_new_channel_type.twitter.description"

- if params[:vimeo]
= link_to(publisher_register_vimeo_channel_omniauth_authorize_path, method: :post, class: 'card block-link--card', :"data-piwik-action" => "AddVimeoChannelClicked", :"data-piwik-name" => "Clicked", :"data-piwik-value" => "AddChannelFlow") do
.new-tag
.card-body
.icon-and-text--icon
= image_tag "choose-channel/vimeo.svg", class: "choose-channel--icon"
.icon-and-text--text
h6= t "publishers.choose_new_channel_type.vimeo.heading"
= t "publishers.choose_new_channel_type.vimeo.description"
= link_to(publisher_register_vimeo_channel_omniauth_authorize_path, method: :post, class: 'card block-link--card', :"data-piwik-action" => "AddVimeoChannelClicked", :"data-piwik-name" => "Clicked", :"data-piwik-value" => "AddChannelFlow") do
.new-tag
.card-body
.icon-and-text--icon
= image_tag "choose-channel/vimeo.svg", class: "choose-channel--icon"
.icon-and-text--text
h6= t "publishers.choose_new_channel_type.vimeo.heading"
= t "publishers.choose_new_channel_type.vimeo.description"

= link_to(publisher_register_reddit_channel_omniauth_authorize_path, method: :post, class: 'card block-link--card', :"data-piwik-action" => "AddRedditChannelClicked", :"data-piwik-name" => "Clicked", :"data-piwik-value" => "AddChannelFlow") do
.new-tag
Expand Down

0 comments on commit 2dbd1c0

Please sign in to comment.