riq 0.9.1 → 1.0.1

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.
@@ -1,89 +0,0 @@
1
- require_relative 'riq_obj'
2
-
3
- module RIQ
4
- # A List is an object that can be created and customized by a User to represent
5
- # Accounts (companies) or Contacts (people) in a process (such as a sales pipeline).
6
- class List < RIQObject
7
- # can't create a list through api, so these don't need to write
8
- attr_reader :title
9
- attr_reader :type
10
- attr_reader :list_items
11
- # for consistency
12
- alias_method :name, :title
13
-
14
- # (see RIQObject#initialize)
15
- def initialize(id = nil)
16
- super
17
- @list_items = ListItemManager.new(@id)
18
- end
19
-
20
- # (see RIQObject#node)
21
- def node
22
- self.class.node(@id)
23
- end
24
-
25
- # (see RIQObject.node)
26
- def self.node(id = nil)
27
- "lists/#{id}"
28
- end
29
-
30
- # (see RIQObject#data)
31
- def data
32
- {
33
- id: @id,
34
- title: @title,
35
- type: @type,
36
- fields: @fields
37
- }
38
- end
39
-
40
- # Overwriting parent because lists can't be saved through the API
41
- def save
42
- raise NotImplementedError, "Lists can't be edited through the API"
43
- end
44
-
45
- # Gets field if it exists
46
- # @param id [String, Integer] field ID
47
- # @return [Hash, nil] info on the field specified
48
- def fields(id = nil)
49
- unless id.nil?
50
- @fields.select{|f| f['id'] == id.to_s}.first
51
- else
52
- @fields
53
- end
54
- end
55
-
56
- # Convenience method for fetching or creating a listitem from the given list
57
- # @param oid [String, nil] ObjectId
58
- def list_item(oid = nil)
59
- RIQ::ListItem.new(oid, lid: @id)
60
- end
61
-
62
- private
63
-
64
- def init(obj = nil)
65
- unless obj.nil?
66
- @id = obj[:id]
67
- @title = obj[:title]
68
- @type = obj[:listType]
69
- @fields = obj[:fields]
70
- else
71
- @id = nil
72
- @title = nil
73
- @type = nil
74
- @fields = nil
75
- end
76
- self
77
- end
78
- end
79
-
80
- class << self
81
- # Convenience method to create new Lists
82
- # @param id [String, nil] create a blank List object or
83
- # fetch an existing one by id.
84
- # @return [List]
85
- def list(id = nil)
86
- List.new(id)
87
- end
88
- end
89
- end
@@ -1,119 +0,0 @@
1
- require_relative 'riq_obj'
2
- using RIQExtensions
3
-
4
- module RIQ
5
- # A List Item is a row in a List.
6
- class ListItem < RIQObject
7
- attr_accessor :name
8
- attr_accessor :field_values
9
- attr_accessor :account_id
10
- attr_accessor :contact_ids
11
- attr_accessor :list_id
12
-
13
- attr_reader :modified_date
14
- attr_reader :created_date
15
-
16
- def initialize(id = nil, lid: nil)
17
- if id.is_a? Hash
18
- super(id)
19
- elsif id.nil? && lid.nil?
20
- super(nil)
21
- elsif id.nil? && !lid.nil?
22
- super(nil)
23
- @list_id = lid
24
- elsif id.nil? || lid.nil?
25
- raise RIQError, 'ObjectID and List ID are required'
26
- else
27
- super("#{lid}/listitems/#{id}")
28
- end
29
- end
30
-
31
- # (see RIQObject#node)
32
- def node
33
- self.class.node(@list_id, @id)
34
- end
35
-
36
- # @note this is the only object for which you have to include two params
37
- # @param lid [String] ListId that the lit item belongs to
38
- # @param oid [String] ObjectId for the object
39
- def self.node(lid = nil, oid = nil)
40
- # weird workaround for fetching node on init
41
- if lid.nil? && !oid.nil?
42
- "lists/#{oid}"
43
- else
44
- "lists/#{lid || @list_id}/listitems/#{oid}"
45
- end
46
- end
47
-
48
- # (see RIQObject#data)
49
- def data
50
- {
51
- name: @name,
52
- account_id: @account_id,
53
- contact_ids: @contact_ids.flatten,
54
- id: @id,
55
- list_id: @list_id,
56
- field_values: @field_values,
57
- modified_date: @modified_date
58
- }
59
- end
60
-
61
- # (see RIQObject#payload)
62
- def payload
63
- pld = {}
64
- data.each do |k, v|
65
- if k == :field_values
66
- pld['fieldValues'] = @field_values.to_raw
67
- elsif k['_']
68
- pld[k.to_cam] = v
69
- else
70
- pld[k] = v
71
- end
72
- end
73
- pld.to_json
74
- end
75
-
76
- # @overload field_value(key)
77
- # @param key [String, Integer]
78
- # @return [Array] Value of key
79
- # @overload field_value(key, value)
80
- # Sets key to value
81
- # @param key [String, Integer] Key to set
82
- # @param value [#to_s] Sets key to value
83
- def field_value(key, value = nil)
84
- # TODO: double check that this works with arrays of stuff
85
- # or, have a format function that casts ints to string on save
86
- if value.nil?
87
- @field_values.fetch(key.to_sym, nil)
88
- else
89
- @field_values[key.to_sym] = value.to_s
90
- {key.to_sym => value.to_s}
91
- end
92
- end
93
-
94
- private
95
-
96
- def init(obj = nil)
97
- unless obj.nil?
98
- @id = obj[:id]
99
- @list_id = obj[:list_id]
100
- @name = obj[:name]
101
- @field_values = obj[:field_values] ? obj[:field_values].from_raw : {}
102
- @account_id = obj[:account_id]
103
- @contact_ids = obj[:contact_ids] || []
104
- @modified_date = obj[:modified_date].cut_milis if obj[:modified_date]
105
- @created_date = obj[:creaeted_date].cut_milis if obj[:creaeted_date]
106
- else
107
- @id = nil
108
- @list_id = nil
109
- @name = nil
110
- @field_values = {}
111
- @account_id = nil
112
- @contact_ids = []
113
- @modified_date = nil
114
- @created_date = nil
115
- end
116
- self
117
- end
118
- end
119
- end
@@ -1,13 +0,0 @@
1
- require_relative 'batch_manager'
2
- require_relative 'list_item'
3
-
4
- module RIQ
5
- # Special child for initializing list items, who need to include extra info.
6
- class ListItemManager < BatchManager
7
- def initialize(lid, page_length = 200)
8
- raise RIQError, 'List id can\'t be nil' if lid.nil?
9
- @list_id = lid
10
- super(RIQ::ListItem, page_length)
11
- end
12
- end
13
- end
@@ -1,104 +0,0 @@
1
- require_relative 'client'
2
- using RIQExtensions
3
-
4
- module RIQ
5
- # @abstract This class should not be used directly.
6
- # Instead, use a child such as {Contact} or {List}.
7
- class RIQObject
8
-
9
-
10
- attr_accessor :id
11
- attr_reader :modified_date
12
-
13
- # @param id [String, Hash] ObjectId or well-formatted hash of data (usually provided by another object
14
- # @return [RIQObject] Self
15
- def initialize(id = nil)
16
- @client = RIQ.client
17
- @id = id
18
-
19
- unless @id.nil?
20
- # data hash
21
- if @id.is_a? Hash
22
- # this looks dumb, could name variables better
23
- data = @id
24
- else
25
- data = @client.get(node)
26
- end
27
- init(data.symbolize)
28
- else
29
- init
30
- end
31
- self
32
- end
33
-
34
- # @return [String] endpoint
35
- def node
36
- raise RIQError, 'This should be overwritten'
37
- end
38
-
39
- # @param id [String] Objectid
40
- # @return [String] endpoint
41
- def self.node(id = nil)
42
- raise RIQError, 'This should be overwritten'
43
- end
44
-
45
- # @return [Hash] all relevant stored data
46
- def data
47
- raise RIQError, 'This should be overwritten'
48
- end
49
-
50
- # @return [String] the json representation of {#data}
51
- def payload
52
- pld = {}
53
- data.each do |k, v|
54
- if k['_']
55
- pld[k.to_cam] = v
56
- else
57
- pld[k] = v
58
- end
59
- end
60
- pld.to_json
61
- end
62
-
63
- # Creates or updates the object
64
- def save(options = nil)
65
- if @id.nil?
66
- # create
67
- init(@client.post(node, payload, options: options).symbolize)
68
- else
69
- # update
70
- init(@client.put(node, payload, options: options).symbolize)
71
- end
72
- end
73
-
74
- # Deletes the object
75
- # @note This is IRREVERSIBLE
76
- def delete
77
- @client.delete(node)
78
- end
79
-
80
- # when you print the object
81
- # def to_s
82
- # JSON.pretty_generate(data)
83
- # data
84
- # end
85
-
86
- # When the object itself is called or returned
87
- def inspect
88
- data
89
- end
90
-
91
- private
92
- def init
93
- raise RIQError, 'This should be overwritten'
94
- end
95
-
96
- # def exists
97
- # if @id.nil?
98
- # false
99
- # else
100
- # @client.fetch(node)
101
- # end
102
- # end
103
- end
104
- end
@@ -1,47 +0,0 @@
1
- require_relative 'riq_obj'
2
-
3
- module RIQ
4
- # Users are represented by owners and contacts in your RelateIQ organization
5
- class User < RIQObject
6
- attr_accessor :name
7
- attr_accessor :email
8
-
9
- # (see RIQObject#node)
10
- def node
11
- "users/#{@id}"
12
- end
13
-
14
- # (see RIQObject#data)
15
- def data
16
- {
17
- id: @id,
18
- name: @name,
19
- email: @email
20
- }
21
- end
22
-
23
- private
24
- def init(obj = nil)
25
- unless obj.nil?
26
- @id = obj[:id]
27
- @name = obj[:name]
28
- @email = obj[:email]
29
- else
30
- @id = nil
31
- @name = nil
32
- @email = nil
33
- end
34
- self
35
- end
36
- end
37
-
38
- class << self
39
- # Convenience method to create new Users
40
- # @param id [String, nil] create a blank User object or
41
- # fetch an existing one by id.
42
- # @return [User]
43
- def user(id = nil)
44
- RIQ::User.new(id)
45
- end
46
- end
47
- end
@@ -1,29 +0,0 @@
1
- # coding: utf-8
2
- # lib = File.expand_path('../lib', __FILE__)
3
- # $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'riq'
7
- spec.version = '0.9.1'
8
- spec.authors = ['David Brownman']
9
- spec.email = ['david@relateiq.com']
10
- spec.homepage = "https://github.com/relateiq/ruby-sdk"
11
- spec.summary = 'Ruby RIQ API client'
12
- spec.description = 'Full featured ruby client for interacting with the RelateIQ API'
13
- spec.license = 'MIT'
14
- spec.files = `git ls-files -z`.split("\x0")
15
- # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ['lib']
18
-
19
- # 2.0 is min becuase use of refinements
20
- spec.required_ruby_version = '>= 2.0.0'
21
- # spec.post_install_message = 'The power of relationship intelligence is in your hands!'
22
-
23
- # prod dependencies
24
- spec.add_dependency 'httparty', '0.13.3'
25
-
26
- # dev dependencies
27
- spec.add_development_dependency 'bundler', '~> 1.7'
28
- # spec.add_development_dependency 'rake', '~> 10.0'
29
- end
@@ -1,4 +0,0 @@
1
- # testing!
2
-
3
- # require everything to run all tests
4
- Dir["#{__dir__}/*_*.rb"].each{|f| require_relative f}
@@ -1,44 +0,0 @@
1
- require 'minitest/autorun'
2
- require_relative '../lib/riq'
3
-
4
- describe RIQ::Account do
5
- before do
6
- RIQ.init
7
- # netflix account ID
8
- @netflix = RIQ.account('54e6542fe4b01ad3b7362bc4')
9
- @a = RIQ.account
10
- @dat = RIQ.account({name: 'Glengarry', field_values: {'0' => 3}})
11
- end
12
-
13
- describe '#new' do
14
- it 'should get account' do
15
- @netflix.name.must_equal 'Netflix'
16
- end
17
-
18
- it 'should make blank account' do
19
- @a.wont_be_nil
20
- end
21
-
22
- it 'should take a data hash' do
23
- @dat = RIQ.account({name: 'David'})
24
- @dat.name.wont_be_nil
25
- end
26
- end
27
-
28
- describe '#save' do
29
- it 'should create new account' do
30
- @a.name = 'Delete Test Inc'
31
- @a.field_value(2, '1')
32
- @a.save
33
-
34
- @a.id.wont_be_nil
35
- end
36
- end
37
-
38
- describe "#field_value" do
39
- it 'should fetch a field value' do
40
- @netflix.field_value(2).wont_be_nil
41
- @dat.field_value(0).wont_be_nil
42
- end
43
- end
44
- end