From 9350f126b4ced4931695f04caa278ad6db8fb3e4 Mon Sep 17 00:00:00 2001 From: Thomas Dziedzic Date: Mon, 9 May 2016 09:44:02 -0700 Subject: [PATCH 1/3] ignore vim files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6ef4a16..0f8da97 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /pkg/ /spec/reports/ /tmp/ +*.swp From 8f7c7c0b498c0ff013c654fae4384b0885c3f426 Mon Sep 17 00:00:00 2001 From: Thomas Dziedzic Date: Mon, 9 May 2016 09:44:28 -0700 Subject: [PATCH 2/3] implement browse_programs --- lib/mrkt.rb | 2 ++ lib/mrkt/concerns/crud_programs.rb | 12 +++++++++ spec/concerns/crud_programs_spec.rb | 42 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/mrkt/concerns/crud_programs.rb create mode 100644 spec/concerns/crud_programs_spec.rb diff --git a/lib/mrkt.rb b/lib/mrkt.rb index 1676f23..90e8822 100644 --- a/lib/mrkt.rb +++ b/lib/mrkt.rb @@ -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 @@ -20,6 +21,7 @@ class Client include CrudLists include ImportLeads include CrudCustomObjects + include CrudPrograms attr_accessor :debug diff --git a/lib/mrkt/concerns/crud_programs.rb b/lib/mrkt/concerns/crud_programs.rb new file mode 100644 index 0000000..7967f39 --- /dev/null +++ b/lib/mrkt/concerns/crud_programs.rb @@ -0,0 +1,12 @@ +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 + end +end diff --git a/spec/concerns/crud_programs_spec.rb b/spec/concerns/crud_programs_spec.rb new file mode 100644 index 0000000..b9cb5e9 --- /dev/null +++ b/spec/concerns/crud_programs_spec.rb @@ -0,0 +1,42 @@ +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 +end From dd4175cc038857a5df050eb0d99d388f581ebde5 Mon Sep 17 00:00:00 2001 From: Thomas Dziedzic Date: Mon, 9 May 2016 10:05:04 -0700 Subject: [PATCH 3/3] implement get_program_by_id --- lib/mrkt/concerns/crud_programs.rb | 4 +++ spec/concerns/crud_programs_spec.rb | 46 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/lib/mrkt/concerns/crud_programs.rb b/lib/mrkt/concerns/crud_programs.rb index 7967f39..344cf27 100644 --- a/lib/mrkt/concerns/crud_programs.rb +++ b/lib/mrkt/concerns/crud_programs.rb @@ -8,5 +8,9 @@ def browse_programs(offset: nil, max_return: nil, status: nil) get('/rest/asset/v1/programs.json', params) end + + def get_program_by_id(id) + get("/rest/asset/v1/program/#{id}.json") + end end end diff --git a/spec/concerns/crud_programs_spec.rb b/spec/concerns/crud_programs_spec.rb index b9cb5e9..ee11d8b 100644 --- a/spec/concerns/crud_programs_spec.rb +++ b/spec/concerns/crud_programs_spec.rb @@ -39,4 +39,50 @@ 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