infunnel_cli 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29bdf4eff04be1ed41c2c767f0b59758e78d08c7
4
- data.tar.gz: 9051898b34982bef33fa0d112238d9d003b2491e
3
+ metadata.gz: faf6be0d4126e71bdb618b23d1cc8e5dc530f78e
4
+ data.tar.gz: 4971635bcf6e381e84dd609c299f03a99688367a
5
5
  SHA512:
6
- metadata.gz: be9da7a876f951e460729d23fa7e00bbffcd0f2bc8355f31b94ad3c83a490fda41f5c81f0378367f66eee69aeec23762eaa2bf2b34e870fb304245e34c075d80
7
- data.tar.gz: 7d07d28f8eb4543486b8559ec5900b350538c405f49786adfe295e09cbe35c1f37053988a9fcf489e21d7c2ce11dbf277852d021bcb161497d5215856b1256ab
6
+ metadata.gz: 26d55e42cdc5c5a134d90972dca56dee0e6451f39f4cd43cebe8effbf6cfc2b1bfaa0780945396486fa83c168e9e259f6c08766a9892396549e2c1f2d42b0e05
7
+ data.tar.gz: 2d0a3a0019253478986d8e1ff4d855e8873e81c5e0d07ab193fb4e5388acb064c467c5fa7f1d4aa17f6aa323a941a928346a4981882e20a351780b132a3eeb88
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/README.md CHANGED
@@ -15,11 +15,16 @@ gem push infunnel_cli-x.x.x.gem
15
15
 
16
16
  Add warnings if no eloqua credentials are stored in keychain.
17
17
 
18
+ ### Misc
18
19
 
20
+ docs for thor: http://whatisthor.com/
19
21
 
22
+ more docs for thor: http://www.rubydoc.info/github/wycats/thor/Thor/Shell/Color
20
23
 
21
- ### Misc
24
+ ### Usage of the cli on mac
22
25
 
23
- docs for thor: http://whatisthor.com/
26
+ pipe results into copy memory: infunnel_cli option_list find 4 --html | pbcopy
27
+
28
+ ## Future improvements
24
29
 
25
- more docs for thor: http://www.rubydoc.info/github/wycats/thor/Thor/Shell/Color
30
+ Make account name editable so you dont have to spell out the full company name
data/bin/infunnel_cli CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'infunnel_cli'
4
4
 
5
- InfunnelCli::HammerOfTheGods.start( ARGV )
5
+ InfunnelCli::Tools.start( ARGV )
data/infunnel_cli.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["lundevallan"]
10
10
  spec.email = ["linus.lundevall@infunnel.se"]
11
11
  spec.summary = "A cli for working with marketing automation."
12
- spec.description = "A cli for working with marketing automation. Connects to the eloqua-api."
12
+ spec.description = "Connects to the eloqua-api. Only works on mac os since it depends on keychain to store credentials."
13
13
  spec.homepage = "http://infunnel.se"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = '~> 2.2'
22
+
21
23
  spec.add_dependency 'thor', '~> 0.19.1'
22
24
  spec.add_dependency 'httparty', '~> 0.13.7'
23
25
  spec.add_dependency 'nokogiri', '1.6.7.2'
@@ -0,0 +1,15 @@
1
+ require 'eloqua_api_service/service'
2
+
3
+ module EloquaApiService
4
+ class Campaign < Service
5
+ BASE_PATH = "/API/REST/2.0"
6
+
7
+ def find(id:)
8
+ parse(self.class.get("#{BASE_PATH}/assets/campaign/#{id}?depth=complete", @options))
9
+ end
10
+
11
+ def all
12
+ parse(self.class.get("#{BASE_PATH}/assets/campaigns?depth=complete", @options))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'eloqua_api_service/service'
2
+ require 'date'
3
+ module EloquaApiService
4
+ class Contact < Service
5
+ BASE_PATH = "/API/REST/1.0"
6
+
7
+ def find(id:)
8
+ parse(self.class.get("#{BASE_PATH}/data/contact/#{id}?depth=complete", @options))
9
+ end
10
+
11
+ def activities(contact_id:)
12
+
13
+ responses = []
14
+ types = ['emailOpen', 'emailSend', 'emailClickThrough', 'emailSubscribe', 'emailUnsubscribe', 'formSubmit', 'webVisit', 'campaignMembership']
15
+ types.each do |type|
16
+ response = self.class.get("#{BASE_PATH}/data/activities/contact/#{contact_id}?type=#{type}&startDate=#{Time.new(2000,7,6).strftime('%s')}&endDate=#{Time.new(2100,7,9).strftime('%s')}&count=1000&depth=complete", @options)
17
+ responses << parse(response) rescue []
18
+ end
19
+ responses
20
+ end
21
+
22
+ def search(term: '')
23
+ parse(self.class.get("#{BASE_PATH}/data/contacts?search=*#{term}*&depth=complete", @options))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ require 'eloqua_api_service/service'
2
+
3
+ module EloquaApiService
4
+ class ContactList < Service
5
+ BASE_PATH = "/API/REST/1.0"
6
+
7
+ def find(id:)
8
+ parse(self.class.get("#{BASE_PATH}/assets/contact/list/#{id}?depth=complete", @options))
9
+ end
10
+
11
+ def all
12
+ parse(self.class.get("#{BASE_PATH}/assets/contact/lists?depth=complete", @options))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'eloqua_api_service/service'
2
+
3
+ module EloquaApiService
4
+ class ContactSegment < Service
5
+ BASE_PATH = "/API/REST/1.0"
6
+
7
+ def find(id:)
8
+ parse(self.class.get("#{BASE_PATH}/assets/contact/segment/#{id}?depth=complete", @options))
9
+ end
10
+
11
+ def all
12
+ parse(self.class.get("#{BASE_PATH}/assets/contact/segments?depth=complete", @options))
13
+ end
14
+ end
15
+ end
@@ -1,25 +1,22 @@
1
1
  module EloquaApiService
2
2
  class Credential
3
3
 
4
- attr_reader :key, :defaults
4
+ attr_reader :key, :options
5
5
 
6
6
  DEFAULT_SERVICE = 'infunnel_cli_default'
7
7
  LABEL = 'infunnel_cli'
8
8
 
9
9
  def initialize
10
10
  @key = nil
11
- @defaults = {
11
+ @options = {
12
12
  label: LABEL
13
13
  }
14
14
  end
15
15
 
16
16
  def find(account: nil)
17
- unless account
18
- @key = default
19
- return @key
20
- end
17
+ return default unless account
21
18
 
22
- @key ||= Keychain.generic_passwords.where(account: account).first
19
+ Keychain.generic_passwords.where(account: account).first
23
20
  end
24
21
 
25
22
  def all
@@ -29,7 +26,7 @@ module EloquaApiService
29
26
  def create(make_default: nil, options: {})
30
27
  find(account: options[:account]).delete if find(account: options[:account])
31
28
 
32
- Keychain.generic_passwords.create(@defaults.merge(options))
29
+ Keychain.generic_passwords.create(@options.merge(options))
33
30
 
34
31
  if make_default || !default
35
32
  set_default(account: options[:account])
@@ -37,18 +34,18 @@ module EloquaApiService
37
34
  end
38
35
 
39
36
  def default
40
- default_account = Keychain.generic_passwords.where(service: DEFAULT_SERVICE).first
41
- if default_account
42
- @default ||= Keychain.generic_passwords.where(account: default_account.account).first
37
+ default_pointer = Keychain.generic_passwords.where(service: DEFAULT_SERVICE).first
38
+ if default_pointer
39
+ @default ||= Keychain.generic_passwords.where(account: default_pointer.account).first
43
40
  end
44
41
  end
45
42
 
46
43
  def set_default(account:)
47
- default = Keychain.generic_passwords.where(service: DEFAULT_SERVICE).first
48
- default.delete if default
44
+ default_pointer = Keychain.generic_passwords.where(service: DEFAULT_SERVICE).first
45
+ default_pointer.delete if default_pointer
49
46
 
50
47
  Keychain.generic_passwords.create({
51
- password: 'none',
48
+ password: '-',
52
49
  service: DEFAULT_SERVICE,
53
50
  account: account
54
51
  })
@@ -0,0 +1,19 @@
1
+ require 'eloqua_api_service/service'
2
+
3
+ module EloquaApiService
4
+ class CustomObject < Service
5
+ BASE_PATH = "/API/REST/1.0"
6
+
7
+ def find(id:)
8
+ parse(self.class.get("#{BASE_PATH}/assets/customObject/#{id}?depth=complete", @options))
9
+ end
10
+
11
+ def all
12
+ parse(self.class.get("#{BASE_PATH}/assets/customObjects?depth=complete", @options))
13
+ end
14
+
15
+ def data_by_id(id:)
16
+ parse(self.class.get("#{BASE_PATH}/data/customObject/#{id}?depth=complete", @options))
17
+ end
18
+ end
19
+ end
@@ -5,6 +5,7 @@ module EloquaApiService
5
5
 
6
6
  def find(id:)
7
7
  response = self.class.get("/API/REST/1.0/assets/email/#{id}", @options)
8
+ puts response.body
8
9
  parsed_response = JSON.parse(response.body, symbolize_names: true) rescue nil
9
10
  end
10
11
 
@@ -2,27 +2,23 @@ require 'eloqua_api_service/service'
2
2
 
3
3
  module EloquaApiService
4
4
  class Form < Service
5
+ BASE_PATH = "/API/REST/1.0"
5
6
 
6
7
  def find(id:)
7
- response = self.class.get("/API/REST/1.0/assets/form/#{id}", @options)
8
- parsed_response = JSON.parse(response.body, symbolize_names: true)
8
+ parse(self.class.get("#{BASE_PATH}/assets/form/#{id}?depth=complete", @options))
9
9
  end
10
10
 
11
11
  def all
12
- response = self.class.get("/API/REST/1.0/assets/forms", @options)
13
- parsed_response = JSON.parse(response.body, symbolize_names: true)
12
+ parse(self.class.get("#{BASE_PATH}/assets/forms?depth=complete", @options))
14
13
  end
15
14
 
16
- def search(term: '', options: {})
17
- parse( self.class.get("/API/REST/1.0/assets/forms?search=*#{term}*&depth=complete", @options) )
15
+ def search(term: '')
16
+ parse(self.class.get("#{BASE_PATH}/assets/forms?search=*#{term}*&depth=complete", @options))
18
17
  end
19
18
 
20
19
  def data(id:, options: {})
21
20
  start_at = options[:start_at] || 0
22
-
23
- response = self.class.get("/API/REST/1.0/data/form/#{id}?startAt=#{start_at.to_i}", @options)
24
- parsed_response = JSON.parse(response.body, symbolize_names: true)
21
+ parse(self.class.get("#{BASE_PATH}/data/form/#{id}?startAt=#{start_at.to_i}", @options))
25
22
  end
26
-
27
23
  end
28
24
  end
@@ -13,7 +13,7 @@ module EloquaApiService
13
13
 
14
14
  def get_options
15
15
  @options = { headers: {
16
- "Authorization" => "Basic #{@credentials.password}",
16
+ 'Authorization' => "Basic #{@credentials.password}",
17
17
  'Content-Type' => 'application/json'
18
18
  },
19
19
  body: {}
@@ -25,7 +25,7 @@ module EloquaApiService
25
25
 
26
26
  @options = {
27
27
  headers: {
28
- "Authorization" => "Basic #{@eloqua_auth}",
28
+ 'Authorization' => "Basic #{@eloqua_auth}",
29
29
  'Content-Type' => 'application/json'
30
30
  },
31
31
  body: {}
@@ -0,0 +1,15 @@
1
+ require 'eloqua_api_service/service'
2
+
3
+ module EloquaApiService
4
+ class OptionList < Service
5
+ BASE_PATH = "/API/REST/1.0"
6
+
7
+ def find(id:)
8
+ parse(self.class.get("#{BASE_PATH}/assets/optionList/#{id}?depth=complete", @options))
9
+ end
10
+
11
+ def all
12
+ parse(self.class.get("#{BASE_PATH}/assets/optionLists?depth=complete", @options))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'eloqua_api_service/service'
2
+
3
+ module EloquaApiService
4
+ class Program < Service
5
+ BASE_PATH = "/API/REST/1.0"
6
+
7
+ def find(id:)
8
+ parse(self.class.get("#{BASE_PATH}/assets/program/#{id}?depth=complete", @options))
9
+ end
10
+
11
+ def all
12
+ parse(self.class.get("#{BASE_PATH}/assets/programs?depth=complete", @options))
13
+ end
14
+
15
+ def find_step(id)
16
+ parse(self.class.get("#{BASE_PATH}/assets/program/step/#{id}?depth=Complete", @options))
17
+ end
18
+ end
19
+ end
@@ -12,7 +12,7 @@ module EloquaApiService
12
12
  self.class.base_uri @credentials.service
13
13
 
14
14
  @options = { headers: {
15
- "Authorization" => "Basic #{@credentials.password}",
15
+ 'Authorization' => "Basic #{@credentials.password}",
16
16
  'Content-Type' => 'application/json'
17
17
  },
18
18
  body: {}
@@ -22,5 +22,9 @@ module EloquaApiService
22
22
  def parse(response)
23
23
  JSON.parse(response.body, symbolize_names: true)
24
24
  end
25
+
26
+ def parse_body(body)
27
+ JSON.parse(body, symbolize_names: true)
28
+ end
25
29
  end
26
30
  end
@@ -0,0 +1,15 @@
1
+ require 'eloqua_api_service/service'
2
+
3
+ module EloquaApiService
4
+ class User < Service
5
+ BASE_PATH = "/API/REST/1.0"
6
+
7
+ def find(id:)
8
+ parse(self.class.get("#{BASE_PATH}/system/user/#{id}?depth=complete", @options))
9
+ end
10
+
11
+ def all
12
+ parse(self.class.get("#{BASE_PATH}/system/users?depth=complete", @options))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'eloqua_api_service/service'
2
+
3
+ module EloquaApiService
4
+ class Visitor < Service
5
+ BASE_PATH = "/API/REST/2.0"
6
+
7
+ def find_by_guid(guid:)
8
+ response = self.class.get("#{BASE_PATH}/data/visitors?search=externalId=#{guid}&page=1&count=5", @options)
9
+ parse(response)
10
+ end
11
+
12
+ def all
13
+ parse(self.class.get("#{BASE_PATH}/data/forms?depth=complete", @options))
14
+ end
15
+
16
+ def search(term: '')
17
+ parse(self.class.get("#{BASE_PATH}/data/forms?search=*#{term}*&depth=complete", @options))
18
+ end
19
+
20
+ def data(id:, options: {})
21
+ start_at = options[:start_at] || 0
22
+ parse(self.class.get("#{BASE_PATH}/data/form/#{id}?startAt=#{start_at.to_i}", @options))
23
+ end
24
+ end
25
+ end
@@ -5,6 +5,15 @@ require 'eloqua_api_service/login'
5
5
  require 'eloqua_api_service/credential'
6
6
  require 'eloqua_api_service/email'
7
7
  require 'eloqua_api_service/form'
8
+ require 'eloqua_api_service/contact'
9
+ require 'eloqua_api_service/visitor'
10
+ require 'eloqua_api_service/option_list'
11
+ require 'eloqua_api_service/program'
12
+ require 'eloqua_api_service/campaign'
13
+ require 'eloqua_api_service/user'
14
+ require 'eloqua_api_service/custom_object'
15
+ require 'eloqua_api_service/contact_segment'
16
+ require 'eloqua_api_service/contact_list'
8
17
 
9
18
  module InfunnelCli
10
19
  module CLI
@@ -12,6 +21,17 @@ module InfunnelCli
12
21
 
13
22
  private
14
23
 
24
+ def format_value(key, value)
25
+ if ['createdAt', 'updatedAt', 'activityDate'].any? { |word| key.to_s.include?(word) }
26
+ return parse_date(value)
27
+ end
28
+ return value
29
+ end
30
+
31
+ def parse_date(unix_date)
32
+ DateTime.strptime(unix_date, '%s').strftime('%Y-%m-%d %H:%M:%S')
33
+ end
34
+
15
35
  def clear(text)
16
36
  "\e[0m#{text}\e[0m"
17
37
  end
@@ -0,0 +1,29 @@
1
+ require 'infunnel_cli/cli/base'
2
+
3
+ module InfunnelCli
4
+ module CLI
5
+ class Campaign < Base
6
+
7
+ desc "find :id", "Show Campaign with id"
8
+ option :account, aliases: :a
9
+ option :format, aliases: :f
10
+ option :html
11
+ def find( id )
12
+ EloquaApiService::Campaign.new(account: options[:account]).find(id: id).each do |k, v|
13
+ puts "#{k}: #{v}"
14
+ end
15
+ end
16
+
17
+ desc "all", "All Campaigns in current eloqua account"
18
+ option :account, aliases: :a
19
+ def all
20
+ EloquaApiService::Campaign.new(account: options[:account]).all[:elements].each do |program|
21
+ puts '-'*90
22
+ program.each do |k, v|
23
+ puts "#{k}: #{v}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,76 @@
1
+ require 'infunnel_cli/cli/base'
2
+
3
+ module InfunnelCli
4
+ module CLI
5
+ class Contact < Base
6
+
7
+ desc "find :id", "Sow form with id"
8
+ option :account, aliases: :a
9
+ option :verbose, aliases: :v
10
+ def find( id )
11
+ contact_print(contacts: [EloquaApiService::Contact.new(account: options[:account]).find(id: id)], options: options)
12
+ end
13
+
14
+ desc "search :term", "Find contact by search"
15
+ option :account, aliases: :a
16
+ option :verbose, aliases: :v
17
+ def search(term)
18
+ contact_print(contacts: EloquaApiService::Contact.new(account: options[:account]).search(term: term)[:elements], options: options)
19
+ end
20
+
21
+ desc "activities :contact_id", "Show activities for contant by id"
22
+ option :account, aliases: :a
23
+ option :verbose, aliases: :v
24
+ def activities(contact_id)
25
+ activities = EloquaApiService::Contact.new(account: options[:account]).activities(contact_id: contact_id)
26
+
27
+ activities.each do |a|
28
+ a.each do |e|
29
+ puts
30
+ e.each do |k, v|
31
+ if k == :details
32
+ puts "#{white k}:"
33
+ v.each do |_k, _v|
34
+ puts "#{ clear _k } #{ clear _v}"
35
+ end
36
+ else
37
+ puts "#{ white k }: #{ clear format_value(k,v)}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ puts activities.count
43
+ end
44
+
45
+ private
46
+
47
+ def contact_print(contacts: [], options: {})
48
+ contacts.each_with_index do |contact, index|
49
+ string = "Id: #{contact[:id]}, "
50
+ string += "emailAddress: #{contact[:emailAddress]}, "
51
+ string += "created_at: #{parse_date(contact[:createdAt])}, "
52
+ string += "updated_at: #{parse_date(contact[:updatedAt])} "
53
+
54
+ if options[:verbose]
55
+ blacklisted = [
56
+ :updatedAt,
57
+ :createdAt,
58
+ :id,
59
+ :emailAddress#,
60
+ #:fieldValues
61
+ ]
62
+
63
+ string += "\n\nFields: \n"
64
+ string += contact.reject{ |k| blacklisted.include?(k) }.map{ |k, v| " #{k}: #{v} \n" }.join('')
65
+ end
66
+ puts index.odd? ? black(on_white(string)) : white(on_black(string))
67
+ puts ''
68
+ end
69
+ end
70
+
71
+ def parse_date(unix_date)
72
+ DateTime.strptime(unix_date, '%s').strftime('%Y-%m-%d %H:%M')
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,30 @@
1
+ require 'infunnel_cli/cli/base'
2
+
3
+ module InfunnelCli
4
+ module CLI
5
+ class ContactList < Base
6
+
7
+ desc "find :id", "Show contact list with id"
8
+ option :account, aliases: :a
9
+ option :format, aliases: :f
10
+ option :html
11
+ def find( id )
12
+ EloquaApiService::ContactList.new(account: options[:account]).find(id: id).each do |k, v|
13
+
14
+ puts "#{k}: #{v}"
15
+ end
16
+ end
17
+
18
+ desc "all", "All contact lists in current eloqua account"
19
+ option :account, aliases: :a
20
+ def all
21
+ EloquaApiService::ContactList.new(account: options[:account]).all[:elements].each do |list|
22
+ puts '-'*90
23
+ list.each do |k, v|
24
+ puts "#{k}: #{v}"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'infunnel_cli/cli/base'
2
+
3
+ module InfunnelCli
4
+ module CLI
5
+ class ContactSegment < Base
6
+
7
+ desc "find :id", "Show contact segment with id"
8
+ option :account, aliases: :a
9
+ option :format, aliases: :f
10
+ option :html
11
+ def find( id )
12
+ EloquaApiService::ContactSegment.new(account: options[:account]).find(id: id).each do |k, v|
13
+
14
+ puts "#{k}: #{v}"
15
+ end
16
+ end
17
+
18
+ desc "all", "All contact segments in current eloqua account"
19
+ option :account, aliases: :a
20
+ def all
21
+ EloquaApiService::ContactSegment.new(account: options[:account]).all[:elements].each do |segment|
22
+ puts '-'*90
23
+ segment.each do |k, v|
24
+ puts "#{k}: #{v}"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,47 @@
1
+ require 'infunnel_cli/cli/base'
2
+
3
+ module InfunnelCli
4
+ module CLI
5
+ class CustomObject < Base
6
+
7
+ desc "find :id", "Show CustomObject with id"
8
+ option :account, aliases: :a
9
+ option :format, aliases: :f
10
+ option :html
11
+ def find( id )
12
+ EloquaApiService::CustomObject.new(account: options[:account]).find(id: id).each do |k, v|
13
+
14
+ puts "#{k}: #{v}"
15
+ end
16
+ end
17
+
18
+ desc "all", "All CustomObjects in current eloqua account"
19
+ option :account, aliases: :a
20
+ def all
21
+ EloquaApiService::CustomObject.new(account: options[:account]).all[:elements].each do |custom_object|
22
+ puts '-'*90
23
+ custom_object.each do |k, v|
24
+ puts "#{k}: #{v}"
25
+ end
26
+ end
27
+ end
28
+
29
+ desc "get data by id", "CustomObjects data by id"
30
+ option :account, aliases: :a
31
+ def data(id)
32
+ EloquaApiService::CustomObject.new(account: options[:account]).data_by_id(id: id)[:elements].each do |custom_object|
33
+ puts '-'*90
34
+ custom_object.each do |k, v|
35
+ if k == :fieldValues
36
+ v.each do |_k, _v|
37
+ puts "#{_k}: #{_v}"
38
+ end
39
+ else
40
+ puts "#{k}: #{v}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -2,7 +2,7 @@ module InfunnelCli
2
2
  module CLI
3
3
  class Eloqua < Base
4
4
 
5
- desc "Login", "Login to eloqua and save credentials in keychain"
5
+ desc "login", "Login to eloqua and save credentials in keychain"
6
6
  option :default, aliases: :d, :type => :boolean
7
7
  def login
8
8
  say("Login to eloqua and save credentials in keychain")
@@ -8,101 +8,158 @@ module InfunnelCli
8
8
  option :links, aliases: :l
9
9
  option :full, aliases: :f
10
10
  option :account, aliases: :a
11
+ option :verbose, aliases: :v
11
12
  def find( id )
12
- puts EloquaApiService::Form.new(account: options[:account]).find(id: 50)
13
- end
13
+ form_print(forms: [EloquaApiService::Form.new(account: options[:account]).find(id: id)], options: options)
14
+ end
15
+
16
+ desc "all", "All forms in current eloqua account"
17
+ option :links, aliases: :l
18
+ option :full, aliases: :f
19
+ option :account, aliases: :a
20
+ option :verbose, aliases: :v
21
+ def all
22
+ form_print(forms: EloquaApiService::Form.new(account: options[:account]).all[:elements], options: options)
23
+ end
24
+
25
+ desc "search :term", "Find form by search on it's name"
26
+ option :account, aliases: :a
27
+ option :verbose, aliases: :v
28
+ def search(term)
29
+ form_print(forms: EloquaApiService::Form.new(account: options[:account]).search(term: term)[:elements], options: options)
30
+ end
14
31
 
15
- desc "all", "All forms in current eloqua account"
16
- option :links, aliases: :l
17
- option :full, aliases: :f
18
- option :account, aliases: :a
19
- def all
20
- puts EloquaApiService::Form.new(account: options[:account]).all[:elements]
21
- end
32
+ desc "data :id", "Get form submissions by form id"
33
+ option :live, aliases: :l
34
+ option :raw, aliases: :r
35
+ option :count, aliases: :c
36
+ option :csv
37
+ option :full, aliases: :f
38
+ option :account, aliases: :a
39
+ def data(form_id)
22
40
 
23
- desc "search :term", "Find form by search on it's name"
24
- option :account, aliases: :a
25
- option :verbose, aliases: :v
26
- def search(term)
27
- EloquaApiService::Form.new(account: options[:account]).search(term: term)[:elements].each_with_index do |form, index|
28
- string = "Id: #{form[:id]}, "
29
- string += "name: #{form[:name]}, "
30
- string += "fields: #{form[:elements].count}, "
31
- string += "created_at: #{parse_date(form[:createdAt])}, "
32
- string += "updated_at: #{parse_date(form[:updatedAt])} "
33
- if options[:verbose]
34
- string += "\n\nFields: \n"
35
- string += form[:elements].map{ |e| " " +
36
- e.reject{ |k| [:style, :validations].include?(k)
37
- }.map{ |k, v| "#{k}: #{v}" }.join(', ')
38
- }.join("\n")
39
- end
40
- puts (index.odd? ? black(on_white(string)) : white(on_black(string)))
41
- puts ''
42
- end
41
+ start_at = options[:full] ? 0 : Time.now - (5*360*24*3600)
42
+ fetch_options = { start_at: start_at, account: options[:account]}
43
+
44
+ form = EloquaApiService::Form.new(account: options[:account]).find(id: form_id)
45
+ elements = form[:elements]
46
+
47
+ unless options[:csv]
48
+ puts black on_white "Form name: #{form[:name]}"
49
+ puts black on_white "Id: #{form[:id]}"
50
+ puts black on_white "Submits after: #{start_at}"
43
51
  end
44
52
 
45
- desc "data :id", "Get form submissions by form id"
46
- option :live, aliases: :l
47
- option :full, aliases: :f
48
- option :account, aliases: :a
49
- def data(form_id)
53
+ submissions = data_fetch(form_id: form_id, options: fetch_options)
50
54
 
51
- start_at = options[:full] ? 0 : Time.now - (76*3600)
52
- fetch_options = { start_at: start_at, account: options[:account] }
55
+ if options[:count]
56
+ puts submissions.size
57
+ return
58
+ end
53
59
 
54
- form = EloquaApiService::Form.new(account: options[:account]).find(id: form_id)
55
- elements = form[:elements]
60
+ if options[:raw]
61
+ puts submissions.to_json
62
+ return
63
+ end
56
64
 
57
- puts black on_white "Form name: " + form[:name]
58
- puts black on_white "Id: " + form[:id]
59
- puts black on_white "Submits after: #{start_at}"
65
+ first = true
66
+
67
+ if options[:live]
68
+ while true
69
+ new_data = data_fetch(form_id: form_id, options: fetch_options)
70
+ data_print(submissions: new_data, elements: elements) if first
60
71
 
61
- submissions = data_fetch(form_id: form_id, options: fetch_options)
72
+ only_new = new_data.reject { |s| submissions.map{ |old| old[:id] }.include?(s[:id]) }
73
+ data_print(submissions: only_new, elements: elements) if only_new != submissions && !first
62
74
 
63
- first = true
75
+ submissions = new_data
76
+ first = false
77
+ sleep 7
78
+ end
79
+ else
80
+ data_print(submissions: submissions, elements: elements, options: { csv: options[:csv] } )
81
+ if options[:full]
82
+ puts "Total submissions: #{submissions.count}"
83
+ end
84
+ end
85
+ end
64
86
 
65
- if options[:live]
66
- while true
67
- new_data = data_fetch(form_id: form_id, options: fetch_options)
68
- data_print(submissions: new_data, elements: elements) if first
87
+ private
69
88
 
70
- only_new = new_data.reject { |s| submissions.map{ |old| old[:id] }.include?(s[:id]) }
71
- data_print(submissions: only_new, elements: elements) if only_new != submissions && !first
89
+ def form_print(forms: [], options: {})
72
90
 
73
- submissions = new_data
74
- first = false
75
- sleep 7
91
+ forms.each_with_index do |form, index|
92
+ string = "Id: #{form[:id]}, "
93
+ string += "name: #{form[:name]}, "
94
+ string += "fields: #{form[:elements].count}, "
95
+ string += "created_at: #{parse_date(form[:createdAt])}, "
96
+ string += "updated_at: #{parse_date(form[:updatedAt])} "
97
+ if options[:verbose]
98
+ string += "\n\nFields: \n"
99
+ string += form[:elements].map{ |e| " " +
100
+ e.reject{ |k| [:style, :validations].include?(k)
101
+ }.map{ |k, v| "#{k}: #{v}" }.join(', ')
102
+ }.join("\n")
103
+ end
104
+ puts (index.odd? ? black(on_white(string)) : white(on_black(string)))
105
+ puts ''
76
106
  end
77
- else
78
- data_print(submissions: submissions, elements: elements)
79
107
  end
80
- end
81
108
 
82
- private
109
+ def data_fetch(form_id: nil, options: {})
110
+ start_at = options[:start_at] || Time.now - (76*3600)
111
+ EloquaApiService::Form.new(account: options[:account]).data(id: form_id, options: {start_at: start_at})[:elements]
112
+ end
83
113
 
84
- def data_fetch(form_id: nil, options: {})
85
- start_at = options[:start_at] || Time.now - (76*3600)
86
- EloquaApiService::Form.new(account: options[:account]).data(id: form_id, options: {start_at: start_at})[:elements]
87
- end
114
+ def data_print(submissions: [], elements: {}, options: {})
115
+
116
+ if options[:csv]
117
+ csv_heading = []
118
+ rows = []
119
+ submissions.reverse.each_with_index do |submission, index|
120
+
121
+ row = []
122
+ if index == 0
123
+ csv_heading = elements.map {|e| e[:htmlName] }
124
+ csv_heading << "submittedAt"
125
+ end
126
+ submission[:fieldValues].each_with_index do |field, index|
127
+ field_name = elements.find { |element| element[:id] == field[:id] }
128
+ row << field[:value] rescue ''
129
+ end
130
+
131
+ rows << row
132
+ row << Time.at(submission[:submittedAt].to_i)
133
+
134
+ end
135
+
136
+ csv_string = CSV.generate do |csv|
137
+ csv << csv_heading
138
+ rows.each do |row|
139
+ csv << row
140
+ end
141
+ end
142
+
143
+ puts csv_string
144
+ return submissions
145
+ end
88
146
 
89
- def data_print(submissions: [], elements: {})
90
- submissions.reverse.each do |submission|
91
- row = []
92
- row << "Id: #{submission[:id]}"
93
- submission[:fieldValues].each do |field|
94
- field_name = elements.find { |element| element[:id] == field[:id] }
95
- row << "#{magenta(field_name[:htmlName])}: #{yellow(field[:value])}"
147
+ submissions.reverse.each do |submission|
148
+ row = []
149
+ row << "Id: #{submission[:id]}"
150
+ submission[:fieldValues].each do |field|
151
+ field_name = elements.find { |element| element[:id] == field[:id] }
152
+ row << "#{magenta(field_name[:htmlName])}: #{yellow(field[:value])}" rescue nil
153
+ end
154
+ row << "At: #{Time.at(submission[:submittedAt].to_i)} \n\n"
155
+ puts row.join(', ')
96
156
  end
97
- row << "At: #{Time.at(submission[:submittedAt].to_i)} \n\n"
98
- puts row.join(', ')
157
+ return submissions
99
158
  end
100
- return submissions
101
- end
102
159
 
103
- def parse_date(unix_date)
104
- DateTime.strptime(unix_date, '%s').strftime('%Y-%m-%d %H:%M')
160
+ def parse_date(unix_date)
161
+ DateTime.strptime(unix_date, '%s').strftime('%Y-%m-%d %H:%M')
162
+ end
105
163
  end
106
164
  end
107
165
  end
108
- end
@@ -0,0 +1,41 @@
1
+ require 'infunnel_cli/cli/base'
2
+
3
+ module InfunnelCli
4
+ module CLI
5
+ class OptionList < Base
6
+
7
+ desc "find :id", "Sow option list with id"
8
+ option :account, aliases: :a
9
+ option :format, aliases: :f
10
+ option :html
11
+ def find( id )
12
+ ol = EloquaApiService::OptionList.new(account: options[:account]).find(id: id)
13
+
14
+ if options[:format]
15
+ ol[:elements].each do |f|
16
+ puts "#{f[:displayName]}|#{f[:value]}"
17
+ end
18
+ elsif options[:html]
19
+ puts "<select name='#{ol[:name]}'>"
20
+ ol[:elements].each do |f|
21
+ puts "<option value='#{f[:value]}'>#{f[:displayName]}</option>"
22
+ end
23
+ puts "</select>"
24
+ else
25
+ puts ol
26
+ end
27
+ end
28
+
29
+ desc "all", "All option lists in current eloqua account"
30
+ option :account, aliases: :a
31
+ def all
32
+ EloquaApiService::OptionList.new(account: options[:account]).all[:elements].each do |ol|
33
+ puts '-' * 90
34
+ ol.each do |k, v|
35
+ puts "#{k}: #{v}"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ require 'infunnel_cli/cli/base'
2
+
3
+ module InfunnelCli
4
+ module CLI
5
+ class Program < Base
6
+
7
+ desc "find :id", "Show program with id"
8
+ option :account, aliases: :a
9
+ option :format, aliases: :f
10
+ option :html
11
+ def find( id )
12
+ EloquaApiService::Program.new(account: options[:account]).find(id: id).each do |k, v|
13
+
14
+ if k == :steps
15
+ puts 'Steps: '
16
+ v.each do |_k, _v|
17
+ find_step(_k[:id])
18
+ end
19
+ else
20
+ puts "#{k}: #{v}"
21
+ end
22
+ end
23
+ end
24
+
25
+ desc "all", "All programs in current eloqua account"
26
+ option :account, aliases: :a
27
+ def all
28
+ EloquaApiService::Program.new(account: options[:account]).all[:elements].each do |program|
29
+ puts '-'*90
30
+ program.each do |k, v|
31
+ puts "#{black on_white k}: #{v}"
32
+ end
33
+ end
34
+ end
35
+
36
+ desc "find_sted", "Find a program step by id"
37
+ option :account, aliases: :a
38
+ def find_step(id)
39
+ puts '-'*90
40
+ EloquaApiService::Program.new(account: options[:account]).find_step(id).each do |k, v|
41
+ puts "#{k}: #{v}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ require 'infunnel_cli/cli/base'
2
+
3
+ module InfunnelCli
4
+ module CLI
5
+ class User < Base
6
+
7
+ desc "find :id", "Show user with id"
8
+ option :account, aliases: :a
9
+ option :format, aliases: :f
10
+ option :html
11
+ def find( id )
12
+ EloquaApiService::User.new(account: options[:account]).find(id: id).each do |k, v|
13
+
14
+ puts "#{k}: #{format_value(k,v)}"
15
+ end
16
+ end
17
+
18
+ desc "all", "All users in current eloqua account"
19
+ option :account, aliases: :a
20
+ def all
21
+ EloquaApiService::User.new(account: options[:account]).all[:elements].each do |user|
22
+ puts '-'*90
23
+ user.each do |k, v|
24
+ puts "#{k}: #{format_value(k,v)}"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ require 'infunnel_cli/cli/base'
2
+ require 'benchmark'
3
+
4
+ module InfunnelCli
5
+ module CLI
6
+ class Visitor < Base
7
+
8
+ desc "find_by_guid :id", "Get form submissions by form id"
9
+ option :live, aliases: :l
10
+ option :full, aliases: :f
11
+ option :account, aliases: :a
12
+ def find_by_guid(guid)
13
+
14
+ response = EloquaApiService::Visitor.new(account: options[:account]).find_by_guid(guid: format_guid(guid))
15
+ response[:elements].each do |e|
16
+ puts '-'*90
17
+ puts e
18
+ end
19
+ puts response
20
+ puts EloquaApiService::Contact.new(account: options[:account]).find(id: response[:elements][0][:contactId]) rescue "No contact id on this visitor."
21
+ end
22
+
23
+ private
24
+
25
+ def format_guid(guid)
26
+ unless guid.include? "-"
27
+ return guid.dup.insert(8, '-').insert(13,'-').insert(18,'-').insert(23,'-').downcase
28
+ end
29
+ guid
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,17 +2,56 @@ require 'thor'
2
2
  require 'infunnel_cli/cli/email'
3
3
  require 'infunnel_cli/cli/eloqua'
4
4
  require 'infunnel_cli/cli/form'
5
+ require 'infunnel_cli/cli/contact'
6
+ require 'infunnel_cli/cli/visitor'
7
+ require 'infunnel_cli/cli/option_list'
8
+ require 'infunnel_cli/cli/program'
9
+ require 'infunnel_cli/cli/campaign'
10
+ require 'infunnel_cli/cli/user'
11
+ require 'infunnel_cli/cli/custom_object'
12
+ require 'infunnel_cli/cli/contact_segment'
13
+ require 'infunnel_cli/cli/contact_list'
5
14
  require 'keychain'
6
15
  #require 'ruby-keychain'
7
16
 
8
17
  module InfunnelCli
9
- class HammerOfTheGods < Thor
18
+ class Tools < Thor
10
19
 
11
- desc "email COMMANDS", ""
20
+ desc "email", ""
12
21
  subcommand "email", InfunnelCli::CLI::Email
13
- desc "login COMMANDS", ""
22
+
23
+ desc "eloqua", ""
14
24
  subcommand "eloqua", InfunnelCli::CLI::Eloqua
15
- desc "form COMMANDS", ""
25
+
26
+ desc "form", ""
16
27
  subcommand "form", InfunnelCli::CLI::Form
28
+
29
+ desc "contact", ""
30
+ subcommand "contact", InfunnelCli::CLI::Contact
31
+
32
+ desc "visitor", ""
33
+ subcommand "visitor", InfunnelCli::CLI::Visitor
34
+
35
+ desc "option_list", ""
36
+ subcommand "option_list", InfunnelCli::CLI::OptionList
37
+
38
+ desc "program", ""
39
+ subcommand "program", InfunnelCli::CLI::Program
40
+
41
+ desc "campaign", ""
42
+ subcommand "campaign", InfunnelCli::CLI::Campaign
43
+
44
+ desc "user", ""
45
+ subcommand "user", InfunnelCli::CLI::User
46
+
47
+ desc "custom_object", ""
48
+ subcommand "custom_object", InfunnelCli::CLI::CustomObject
49
+
50
+ desc "contact_segment", ""
51
+ subcommand "contact_segment", InfunnelCli::CLI::ContactSegment
52
+
53
+ desc "contact_list", ""
54
+ subcommand "contact_list", InfunnelCli::CLI::ContactList
55
+
17
56
  end
18
57
  end
@@ -1,3 +1,3 @@
1
1
  module InfunnelCli
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infunnel_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - lundevallan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-23 00:00:00.000000000 Z
11
+ date: 2016-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -114,7 +114,8 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: 11.2.2
117
- description: A cli for working with marketing automation. Connects to the eloqua-api.
117
+ description: Connects to the eloqua-api. Only works on mac os since it depends on
118
+ keychain to store credentials.
118
119
  email:
119
120
  - linus.lundevall@infunnel.se
120
121
  executables:
@@ -122,7 +123,6 @@ executables:
122
123
  extensions: []
123
124
  extra_rdoc_files: []
124
125
  files:
125
- - ".DS_Store"
126
126
  - ".gitignore"
127
127
  - Gemfile
128
128
  - LICENSE.txt
@@ -130,17 +130,35 @@ files:
130
130
  - Rakefile
131
131
  - bin/infunnel_cli
132
132
  - infunnel_cli.gemspec
133
+ - lib/eloqua_api_service/campaign.rb
134
+ - lib/eloqua_api_service/contact.rb
135
+ - lib/eloqua_api_service/contact_list.rb
136
+ - lib/eloqua_api_service/contact_segment.rb
133
137
  - lib/eloqua_api_service/credential.rb
138
+ - lib/eloqua_api_service/custom_object.rb
134
139
  - lib/eloqua_api_service/email.rb
135
140
  - lib/eloqua_api_service/form.rb
136
141
  - lib/eloqua_api_service/login.rb
142
+ - lib/eloqua_api_service/option_list.rb
143
+ - lib/eloqua_api_service/program.rb
137
144
  - lib/eloqua_api_service/service.rb
145
+ - lib/eloqua_api_service/user.rb
146
+ - lib/eloqua_api_service/visitor.rb
138
147
  - lib/infunnel_cli.rb
139
148
  - lib/infunnel_cli/cli.rb
140
149
  - lib/infunnel_cli/cli/base.rb
150
+ - lib/infunnel_cli/cli/campaign.rb
151
+ - lib/infunnel_cli/cli/contact.rb
152
+ - lib/infunnel_cli/cli/contact_list.rb
153
+ - lib/infunnel_cli/cli/contact_segment.rb
154
+ - lib/infunnel_cli/cli/custom_object.rb
141
155
  - lib/infunnel_cli/cli/eloqua.rb
142
156
  - lib/infunnel_cli/cli/email.rb
143
157
  - lib/infunnel_cli/cli/form.rb
158
+ - lib/infunnel_cli/cli/option_list.rb
159
+ - lib/infunnel_cli/cli/program.rb
160
+ - lib/infunnel_cli/cli/user.rb
161
+ - lib/infunnel_cli/cli/visitor.rb
144
162
  - lib/infunnel_cli/version.rb
145
163
  homepage: http://infunnel.se
146
164
  licenses:
@@ -152,9 +170,9 @@ require_paths:
152
170
  - lib
153
171
  required_ruby_version: !ruby/object:Gem::Requirement
154
172
  requirements:
155
- - - ">="
173
+ - - "~>"
156
174
  - !ruby/object:Gem::Version
157
- version: '0'
175
+ version: '2.2'
158
176
  required_rubygems_version: !ruby/object:Gem::Requirement
159
177
  requirements:
160
178
  - - ">="
data/.DS_Store DELETED
Binary file