Skip to content

Commit

Permalink
Merge pull request #2 from shopsmart/list_canvas_endpoint
Browse files Browse the repository at this point in the history
List canvas endpoint
  • Loading branch information
Allen authored Jan 25, 2021
2 parents 584ae75 + 10f9861 commit 9bc9529
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ See: [Segment Export](https://www.braze.com/documentation/REST_API/#segment-expo
api.list_segments
```

### List Canvas

See: [Segment Export](https://www.braze.com/docs/api/endpoints/export/canvas/get_canvases)

```ruby
api.list_canvas(
sort_direction: (optional, string, default: 'desc',
include_archived: (optional, boolean, default: false)
)
```

### Export Users

See: [User Export](https://www.braze.com/documentation/REST_API/#user-export)
Expand Down
3 changes: 3 additions & 0 deletions lib/appboy/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'appboy/endpoints/email_status'
require 'appboy/endpoints/trigger_campaign'
require 'appboy/endpoints/trigger_canvas'
require 'appboy/endpoints/list_canvas'

module Appboy
class API
Expand All @@ -18,6 +19,7 @@ class API
include Appboy::Endpoints::EmailStatus
include Appboy::Endpoints::TriggerCampaign
include Appboy::Endpoints::TriggerCanvas
include Appboy::Endpoints::ListCanvas

def export_users(**payload)
Appboy::REST::ExportUsers.new.perform(app_group_id, payload)
Expand All @@ -34,3 +36,4 @@ def initialize(app_group_id)
end
end
end

15 changes: 15 additions & 0 deletions lib/appboy/endpoints/list_canvas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Appboy
module Endpoints
module ListCanvas
def list_canvas(**payload)
list_canvas_service.new(app_group_id, payload).perform
end

private

def list_canvas_service
Appboy::REST::ListCanvas
end
end
end
end
1 change: 1 addition & 0 deletions lib/appboy/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
require 'appboy/rest/list_segments'
require 'appboy/rest/trigger_campaign'
require 'appboy/rest/trigger_canvas'
require 'appboy/rest/list_canvas'
21 changes: 21 additions & 0 deletions lib/appboy/rest/list_canvas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Appboy
module REST
class ListCanvas < Base
attr_reader :app_group_id, :sort_direction, :include_archived

def initialize(app_group_id, options = {})
@app_group_id = app_group_id
@sort_direction = options[:sort_direction]
@include_archived = options[:include_archived]
end

def perform
http.get '/canvas/list', {
app_group_id: app_group_id,
sort_direction: sort_direction,
include_archived: include_archived
}.compact
end
end
end
end
2 changes: 1 addition & 1 deletion lib/appboy/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Appboy
VERSION = '0.1.6'
VERSION = '0.1.7'
end
23 changes: 23 additions & 0 deletions spec/appboy/rest/list_canvas_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe Appboy::REST::ListCanvas do
let(:http) { double(:http) }

let(:payload) {{
sort_direction: "desc",
include_archived: false
}}

let(:app_group_id) { :app_group_id }

subject { described_class.new(:app_group_id, sort_direction: "desc", include_archived: false) }

before { subject.http = http }

it 'makes an http call to the list canvas endpoint' do
expect(http).to receive(:get).with '/canvas/list',
payload.merge({ app_group_id: :app_group_id })

subject.perform
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions spec/integrations/list_canvas_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

describe 'list canvas' do
subject(:list_canvas) { api.list_canvas }

context 'with success', :vcr do
it 'responds with success' do
expect(list_canvas).to be_success
end

it 'responds with a list of segments' do
expect(canvases.count).to be 4

expect(canvases.first['name']).to eq 'ONBOARDING_NEW SUBSCRIBERS'
end

def canvases
JSON.parse(list_canvas.body)['canvases']
end
end
end

0 comments on commit 9bc9529

Please sign in to comment.