Skip to content

Commit

Permalink
Merge pull request #14 from PagerDuty/browse-programs
Browse files Browse the repository at this point in the history
feat(programs): add API calls for program reading
  • Loading branch information
raszi committed May 10, 2016
2 parents 6358b90 + dd4175c commit 9cdeeb2
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/pkg/
/spec/reports/
/tmp/
*.swp
2 changes: 2 additions & 0 deletions lib/mrkt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'mrkt/concerns/crud_lists'
require 'mrkt/concerns/import_leads'
require 'mrkt/concerns/crud_custom_objects'
require 'mrkt/concerns/crud_programs'

module Mrkt
class Client
Expand All @@ -20,6 +21,7 @@ class Client
include CrudLists
include ImportLeads
include CrudCustomObjects
include CrudPrograms

attr_accessor :debug

Expand Down
16 changes: 16 additions & 0 deletions lib/mrkt/concerns/crud_programs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Mrkt
module CrudPrograms
def browse_programs(offset: nil, max_return: nil, status: nil)
params = {}
params[:offset] = offset if offset
params[:maxReturn] = max_return if max_return
params[:status] = status if status

get('/rest/asset/v1/programs.json', params)
end

def get_program_by_id(id)
get("/rest/asset/v1/program/#{id}.json")
end
end
end
88 changes: 88 additions & 0 deletions spec/concerns/crud_programs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
describe Mrkt::CrudPrograms do
include_context 'initialized client'

describe '#browse_programs' do
let(:response_stub) do
{
success: true,
warnings: [],
errors: [],
requestId: '7a39#1511bf8a41c',
result: [
{
id: 1035,
name: 'clone it',
description: '',
createdAt: '2015-11-18T15:25:35Z+0000',
updatedAt: '2015-11-18T15:25:46Z+0000',
url: 'https://app-devlocal1.marketo.com/#NP1035A1',
type: 'Engagement',
channel: 'Nurture',
folder: {
type: 'Folder',
value: 28,
folderName: 'Nurturing'
},
status: 'on',
workspace: 'Default'
}
]
}
end

subject { client.browse_programs }

before do
stub_request(:get, "https://#{host}/rest/asset/v1/programs.json")
.to_return(json_stub(response_stub))
end

it { is_expected.to eq(response_stub) }
end

describe '#get_program_by_id' do
let(:response_stub) do
{
success: true,
warnings: [],
errors: [],
requestId: '948f#14db037ec71',
result: [
{
id: 1107,
name: 'AAA2QueryProgramName',
description: 'AssetAPI: getProgram tests',
createdAt: '2015-05-21T22:45:13Z+0000',
updatedAt: '2015-05-21T22:45:13Z+0000',
url: 'https://app-devlocal1.marketo.com/#PG1107A1',
type: 'Default',
channel: 'Online Advertising',
folder: {
type: 'Folder',
value: 1910,
folderName: 'ProgramQueryTestFolder'
},
status: '',
workspace: 'Default',
tags: [
{
tagType: 'AAA1 Required Tag Type',
tagValue: 'AAA1 RT1'
}
],
costs: nil
}
]
}
end

subject { client.get_program_by_id(1107) }

before do
stub_request(:get, "https://#{host}/rest/asset/v1/program/1107.json")
.to_return(json_stub(response_stub))
end

it { is_expected.to eq(response_stub) }
end
end

0 comments on commit 9cdeeb2

Please sign in to comment.