riq 0.8.8 → 0.9.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.
- checksums.yaml +4 -4
- data/lib/riq.rb +100 -4
- data/lib/riq/account.rb +9 -7
- data/lib/riq/batch_manager.rb +7 -3
- data/lib/riq/contact.rb +20 -2
- data/lib/riq/event.rb +8 -5
- data/lib/riq/list.rb +4 -4
- data/lib/riq/{listitem.rb → list_item.rb} +14 -13
- data/lib/riq/list_item_manager.rb +1 -0
- data/lib/riq/riq_obj.rb +8 -59
- data/lib/riq/user.rb +3 -3
- data/riq.gemspec +3 -2
- data/test/test.rb +1 -1
- data/test/test_account.rb +8 -3
- data/test/test_batch_manager.rb +27 -0
- data/test/test_contact.rb +13 -1
- data/test/test_event.rb +56 -0
- data/test/test_list_item.rb +42 -0
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 298db01f6539c6549b61843f84e90c13e3392c44
|
4
|
+
data.tar.gz: cf5dd577bd23f093e1112504a7713ced7da69e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b491d52bd9c27e4c6f9873b24888d4037492b4e20cf90fb9e005b82642caf0003deccc7b017b4971dd48905dcbeedb47adf776d553b60f8def3046ad740d87f2
|
7
|
+
data.tar.gz: 7ecd4d753690f5d1661357a65bf49490a0d09fd1592067df167bce4f833ec25297551658b37de7f467801ce80d2e64e5fe8288d53b3dea8b254c08e7d04d3c01
|
data/lib/riq.rb
CHANGED
@@ -1,7 +1,103 @@
|
|
1
|
-
# Base file from which everything else is included
|
2
|
-
Dir[__dir__ + '/riq/*.rb'].each {|file| require file }
|
3
|
-
|
4
1
|
# The namespace from which all magic springs
|
5
2
|
module RIQ
|
6
3
|
# Could fetch defaults or something here
|
7
|
-
end
|
4
|
+
end
|
5
|
+
|
6
|
+
# Monekypatches
|
7
|
+
# cry about it, nerd
|
8
|
+
module RIQExtensions
|
9
|
+
refine Symbol do
|
10
|
+
def to_cam
|
11
|
+
temp = self.to_s.split('_').map(&:capitalize).join
|
12
|
+
(temp[0].downcase + temp[1..-1]).to_sym
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_snake
|
16
|
+
a = self.to_s.split('')
|
17
|
+
n = []
|
18
|
+
a.each do |l|
|
19
|
+
n << '_' if l.is_upper?
|
20
|
+
n << l.downcase
|
21
|
+
end
|
22
|
+
n = n[1..-1] if n.first == '_'
|
23
|
+
n.join.to_sym
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
refine String do
|
28
|
+
def is_upper?
|
29
|
+
!self[/[A-Z]/].nil? && self.length == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_lower?
|
33
|
+
!self[/[a-z]/].nil? && self.length == 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
refine Fixnum do
|
38
|
+
def cut_milis
|
39
|
+
self.to_s[0...-3].to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_sym
|
43
|
+
self.to_s.to_sym
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
refine Hash do
|
48
|
+
# Converts to RIQ API's [{raw: "VALUE"}] format
|
49
|
+
def to_raw
|
50
|
+
return {} if self.empty?
|
51
|
+
o = {}
|
52
|
+
self.each do |k, v|
|
53
|
+
o[k.to_cam] = [{raw: v}]
|
54
|
+
end
|
55
|
+
o
|
56
|
+
end
|
57
|
+
|
58
|
+
# Converts from RIQ API's [{raw: "VALUE"}] format
|
59
|
+
def from_raw
|
60
|
+
return {} if self.empty?
|
61
|
+
o = {}
|
62
|
+
self.each do |k,v|
|
63
|
+
if v.is_a?(Array) && v.first.include?(:raw)
|
64
|
+
o[k.to_sym.to_snake] = v.first[:raw]
|
65
|
+
else
|
66
|
+
o[k.to_sym.to_snake] = v
|
67
|
+
end
|
68
|
+
end
|
69
|
+
o
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_cam
|
73
|
+
o = {}
|
74
|
+
self.each do |k,v|
|
75
|
+
o[k.to_cam] = v
|
76
|
+
end
|
77
|
+
o
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
refine Object do
|
82
|
+
def symbolize
|
83
|
+
return self unless self.respond_to? :keys
|
84
|
+
o = {}
|
85
|
+
self.each do |k, v|
|
86
|
+
if v.respond_to? :keys
|
87
|
+
o[k.to_sym.to_snake] = v.symbolize
|
88
|
+
else
|
89
|
+
if v.respond_to? :each
|
90
|
+
v.map! do |i|
|
91
|
+
i.symbolize
|
92
|
+
end
|
93
|
+
end
|
94
|
+
o[k.to_sym.to_snake] = v
|
95
|
+
end
|
96
|
+
end
|
97
|
+
o
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Base file from which everything else is included
|
103
|
+
Dir[__dir__ + '/riq/*.rb'].each {|file| require file }
|
data/lib/riq/account.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'riq_obj'
|
2
|
+
using RIQExtensions
|
2
3
|
|
3
4
|
module RIQ
|
4
5
|
# Accounts represent companies (or other entities).
|
@@ -29,7 +30,7 @@ module RIQ
|
|
29
30
|
def payload
|
30
31
|
# TODO: find more elegant way to do this
|
31
32
|
pld = data
|
32
|
-
pld['fieldValues'] =
|
33
|
+
pld['fieldValues'] = @field_values.to_raw
|
33
34
|
pld.delete(:field_values)
|
34
35
|
pld.to_json
|
35
36
|
end
|
@@ -45,19 +46,20 @@ module RIQ
|
|
45
46
|
# TODO: double check that this works with arrays of stuff
|
46
47
|
# or, have a format function that casts ints to string on save
|
47
48
|
if value.nil?
|
48
|
-
@field_values.fetch(key.
|
49
|
+
@field_values.fetch(key.to_sym, nil)
|
49
50
|
else
|
50
|
-
@field_values[key.
|
51
|
-
{key.
|
51
|
+
@field_values[key.to_sym] = value.to_s
|
52
|
+
{key.to_sym => value.to_s}
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
55
56
|
private
|
56
57
|
def init(obj = nil)
|
57
58
|
unless obj.nil?
|
58
|
-
@id = obj[
|
59
|
-
@name = obj[
|
60
|
-
@field_values =
|
59
|
+
@id = obj[:id]
|
60
|
+
@name = obj[:name]
|
61
|
+
@field_values = obj[:field_values] ? obj[:field_values].from_raw : {}
|
62
|
+
@modified_date = obj[:modified_date].cut_milis if obj[:modified_date]
|
61
63
|
else
|
62
64
|
@id = nil
|
63
65
|
@name = nil
|
data/lib/riq/batch_manager.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
using RIQExtensions
|
2
|
+
|
1
3
|
module RIQ
|
2
4
|
# Manages caching and fetching for a certain type of child object.
|
3
5
|
class BatchManager
|
@@ -6,7 +8,8 @@ module RIQ
|
|
6
8
|
|
7
9
|
# @param klass [RIQObject] The child class that's being fetched, such as {Account} or {List}
|
8
10
|
# @param page_length [Integer] The number of items per page
|
9
|
-
|
11
|
+
# @param opts [Hash] fetch options
|
12
|
+
def initialize(klass, page_length = 200, opts: {})
|
10
13
|
@klass = klass
|
11
14
|
begin
|
12
15
|
raise unless @klass.ancestors.include? RIQ::RIQObject
|
@@ -17,7 +20,7 @@ module RIQ
|
|
17
20
|
reset_cache
|
18
21
|
# ruby says that nil is an argument and page_size was getting set to 0
|
19
22
|
@page_length = page_length.nil? ? 200 : page_length
|
20
|
-
|
23
|
+
self.send(:fetch_options=, opts)
|
21
24
|
@client = RIQ.client
|
22
25
|
end
|
23
26
|
|
@@ -58,11 +61,12 @@ module RIQ
|
|
58
61
|
options[k] = v
|
59
62
|
end
|
60
63
|
end
|
61
|
-
@fetch_options = options
|
64
|
+
@fetch_options = options#.to_cam
|
62
65
|
end
|
63
66
|
|
64
67
|
private
|
65
68
|
def next_item
|
69
|
+
# I believe this is resetting opts somehow/not respecting limit
|
66
70
|
if @cache_index == @cache.size
|
67
71
|
return nil if ![0, @page_length].include? @cache.size
|
68
72
|
# puts "\n=== fetching page! (#{@page_index}) (#{@page_length})"
|
data/lib/riq/contact.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'riq_obj'
|
2
|
+
using RIQExtensions
|
2
3
|
|
3
4
|
module RIQ
|
4
5
|
# Contacts represent people in an Organization’s address book.
|
@@ -20,6 +21,7 @@ module RIQ
|
|
20
21
|
{
|
21
22
|
id: @id,
|
22
23
|
properties: @properties
|
24
|
+
# modified_date: @modified_date
|
23
25
|
}
|
24
26
|
end
|
25
27
|
|
@@ -57,8 +59,11 @@ module RIQ
|
|
57
59
|
val.each do |i|
|
58
60
|
add(prop, i)
|
59
61
|
end
|
62
|
+
return
|
60
63
|
end
|
61
64
|
|
65
|
+
raise RIQError, 'Values must be strings' unless val.is_a? String
|
66
|
+
|
62
67
|
# don't add duplicate
|
63
68
|
if @properties[prop].select{|p| p[:value] == val}.empty?
|
64
69
|
@properties[prop] << {value: val, metadata: {}}
|
@@ -105,8 +110,21 @@ module RIQ
|
|
105
110
|
|
106
111
|
def init(obj = nil)
|
107
112
|
unless obj.nil?
|
108
|
-
@id = obj[
|
109
|
-
@
|
113
|
+
@id = obj[:id]
|
114
|
+
@modified_date = obj[:modified_date].cut_milis if obj[:modified_date]
|
115
|
+
@properties = {}
|
116
|
+
obj[:properties].each do |k,v|
|
117
|
+
raise RIQError, "Properties must be arrays, #{k} wasn't" if !v.is_a?(Array)
|
118
|
+
|
119
|
+
v.each do |i|
|
120
|
+
unless i.is_a?(Hash)
|
121
|
+
add(k, i)
|
122
|
+
else
|
123
|
+
@properties[k] = [] unless @properties.include?(k)
|
124
|
+
@properties[k] << i
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
110
128
|
else
|
111
129
|
@id = nil
|
112
130
|
@properties = {}
|
data/lib/riq/event.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'riq_obj'
|
2
|
+
using RIQExtensions
|
2
3
|
|
3
4
|
module RIQ
|
4
5
|
# Events represent interactions involving a Contact associated with a List Item.
|
@@ -48,9 +49,10 @@ module RIQ
|
|
48
49
|
private
|
49
50
|
def init(obj = nil)
|
50
51
|
unless obj.nil?
|
51
|
-
@subject = obj[
|
52
|
-
@body = obj[
|
53
|
-
@participant_ids =
|
52
|
+
@subject = obj[:subject]
|
53
|
+
@body = obj[:body]
|
54
|
+
@participant_ids = []
|
55
|
+
obj[:participant_ids].each{|o| add_participant(o[:type], o[:value])}
|
54
56
|
else
|
55
57
|
@subject = nil
|
56
58
|
@body = nil
|
@@ -62,9 +64,10 @@ module RIQ
|
|
62
64
|
|
63
65
|
class << self
|
64
66
|
# Convenience method to create new Events
|
67
|
+
# @param obj [Hash] Info to parse into event
|
65
68
|
# @return [Event]
|
66
|
-
def event
|
67
|
-
Event.new
|
69
|
+
def event(obj = nil)
|
70
|
+
Event.new(obj)
|
68
71
|
end
|
69
72
|
end
|
70
73
|
end
|
data/lib/riq/list.rb
CHANGED
@@ -63,10 +63,10 @@ module RIQ
|
|
63
63
|
|
64
64
|
def init(obj = nil)
|
65
65
|
unless obj.nil?
|
66
|
-
@id = obj[
|
67
|
-
@title = obj[
|
68
|
-
@type = obj[
|
69
|
-
@fields = obj[
|
66
|
+
@id = obj[:id]
|
67
|
+
@title = obj[:title]
|
68
|
+
@type = obj[:listType]
|
69
|
+
@fields = obj[:fields]
|
70
70
|
else
|
71
71
|
@id = nil
|
72
72
|
@title = nil
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'riq_obj'
|
2
|
+
using RIQExtensions
|
2
3
|
|
3
4
|
module RIQ
|
4
5
|
# A List Item is a row in a List.
|
@@ -62,9 +63,9 @@ module RIQ
|
|
62
63
|
pld = {}
|
63
64
|
data.each do |k, v|
|
64
65
|
if k == :field_values
|
65
|
-
pld['fieldValues'] =
|
66
|
+
pld['fieldValues'] = @field_values.to_raw
|
66
67
|
elsif k['_']
|
67
|
-
pld[
|
68
|
+
pld[k.to_cam] = v
|
68
69
|
else
|
69
70
|
pld[k] = v
|
70
71
|
end
|
@@ -83,10 +84,10 @@ module RIQ
|
|
83
84
|
# TODO: double check that this works with arrays of stuff
|
84
85
|
# or, have a format function that casts ints to string on save
|
85
86
|
if value.nil?
|
86
|
-
@field_values.fetch(key.
|
87
|
+
@field_values.fetch(key.to_sym, nil)
|
87
88
|
else
|
88
|
-
@field_values[key.
|
89
|
-
{key.
|
89
|
+
@field_values[key.to_sym] = value.to_s
|
90
|
+
{key.to_sym => value.to_s}
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
@@ -94,14 +95,14 @@ module RIQ
|
|
94
95
|
|
95
96
|
def init(obj = nil)
|
96
97
|
unless obj.nil?
|
97
|
-
@id = obj[
|
98
|
-
@list_id = obj[
|
99
|
-
@name = obj[
|
100
|
-
@field_values =
|
101
|
-
@account_id = obj[
|
102
|
-
@contact_ids = obj[
|
103
|
-
@modified_date = obj[
|
104
|
-
@created_date = obj[
|
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]
|
105
106
|
else
|
106
107
|
@id = nil
|
107
108
|
@list_id = nil
|
data/lib/riq/riq_obj.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require_relative 'client'
|
2
|
+
using RIQExtensions
|
2
3
|
|
3
4
|
module RIQ
|
4
5
|
# @abstract This class should not be used directly.
|
5
6
|
# Instead, use a child such as {Contact} or {List}.
|
6
7
|
class RIQObject
|
8
|
+
|
9
|
+
|
7
10
|
attr_accessor :id
|
8
|
-
|
11
|
+
attr_reader :modified_date
|
9
12
|
|
10
13
|
# @param id [String, Hash] ObjectId or well-formatted hash of data (usually provided by another object
|
11
14
|
# @return [RIQObject] Self
|
@@ -21,7 +24,7 @@ module RIQ
|
|
21
24
|
else
|
22
25
|
data = @client.get(node)
|
23
26
|
end
|
24
|
-
init(data)
|
27
|
+
init(data.symbolize)
|
25
28
|
else
|
26
29
|
init
|
27
30
|
end
|
@@ -49,7 +52,7 @@ module RIQ
|
|
49
52
|
pld = {}
|
50
53
|
data.each do |k, v|
|
51
54
|
if k['_']
|
52
|
-
pld[
|
55
|
+
pld[k.to_cam] = v
|
53
56
|
else
|
54
57
|
pld[k] = v
|
55
58
|
end
|
@@ -61,10 +64,10 @@ module RIQ
|
|
61
64
|
def save(options = nil)
|
62
65
|
if @id.nil?
|
63
66
|
# create
|
64
|
-
init(@client.post(node, payload, options: options))
|
67
|
+
init(@client.post(node, payload, options: options).symbolize)
|
65
68
|
else
|
66
69
|
# update
|
67
|
-
init(@client.put(node, payload, options: options))
|
70
|
+
init(@client.put(node, payload, options: options).symbolize)
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
@@ -90,51 +93,6 @@ module RIQ
|
|
90
93
|
raise RIQError, 'This should be overwritten'
|
91
94
|
end
|
92
95
|
|
93
|
-
# Converts to RIQ API's [{raw: "VALUE"}] format
|
94
|
-
def to_raw(hsh)
|
95
|
-
return {} if hsh.empty?
|
96
|
-
obj = {}
|
97
|
-
hsh.each do |k, v|
|
98
|
-
obj[k] = [{raw: v}]
|
99
|
-
end
|
100
|
-
obj
|
101
|
-
end
|
102
|
-
|
103
|
-
# Converts from RIQ API's [{raw: "VALUE"}] format
|
104
|
-
def from_raw(hsh)
|
105
|
-
return {} if hsh.empty?
|
106
|
-
obj = {}
|
107
|
-
hsh.each do |k,v|
|
108
|
-
obj[k] = v.first['raw']
|
109
|
-
end
|
110
|
-
obj
|
111
|
-
end
|
112
|
-
|
113
|
-
def camel_case(sym)
|
114
|
-
temp = sym.to_s.split('_').map(&:capitalize).join
|
115
|
-
temp[0].downcase + temp[1..-1]
|
116
|
-
end
|
117
|
-
|
118
|
-
# make everything a symbol
|
119
|
-
def symbolize(h)
|
120
|
-
return h unless h.respond_to? :keys
|
121
|
-
|
122
|
-
obj = {}
|
123
|
-
h.each do |k, v|
|
124
|
-
if v.respond_to? :keys
|
125
|
-
obj[k.to_sym] = symbolize(v)
|
126
|
-
else
|
127
|
-
if v.respond_to? :each
|
128
|
-
v.map! do |i|
|
129
|
-
symbolize(i)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
obj[k.to_sym] = v
|
133
|
-
end
|
134
|
-
end
|
135
|
-
obj
|
136
|
-
end
|
137
|
-
|
138
96
|
# def exists
|
139
97
|
# if @id.nil?
|
140
98
|
# false
|
@@ -142,14 +100,5 @@ module RIQ
|
|
142
100
|
# @client.fetch(node)
|
143
101
|
# end
|
144
102
|
# end
|
145
|
-
|
146
103
|
end
|
147
|
-
|
148
|
-
# Monkeypatches
|
149
|
-
# class Symbol
|
150
|
-
# def camel_case
|
151
|
-
# temp = self.to_s.split('_').map(&:capitalize).join
|
152
|
-
# temp[0].downcase + temp[1..-1]
|
153
|
-
# end
|
154
|
-
# end
|
155
104
|
end
|
data/lib/riq/user.rb
CHANGED
data/riq.gemspec
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'riq'
|
7
|
-
spec.version = '0.
|
7
|
+
spec.version = '0.9.1'
|
8
8
|
spec.authors = ['David Brownman']
|
9
9
|
spec.email = ['david@relateiq.com']
|
10
10
|
spec.homepage = "https://github.com/relateiq/ruby-sdk"
|
@@ -16,7 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
|
-
|
19
|
+
# 2.0 is min becuase use of refinements
|
20
|
+
spec.required_ruby_version = '>= 2.0.0'
|
20
21
|
# spec.post_install_message = 'The power of relationship intelligence is in your hands!'
|
21
22
|
|
22
23
|
# prod dependencies
|
data/test/test.rb
CHANGED
data/test/test_account.rb
CHANGED
@@ -7,6 +7,7 @@ describe RIQ::Account do
|
|
7
7
|
# netflix account ID
|
8
8
|
@netflix = RIQ.account('54e6542fe4b01ad3b7362bc4')
|
9
9
|
@a = RIQ.account
|
10
|
+
@dat = RIQ.account({name: 'Glengarry', field_values: {'0' => 3}})
|
10
11
|
end
|
11
12
|
|
12
13
|
describe '#new' do
|
@@ -14,9 +15,14 @@ describe RIQ::Account do
|
|
14
15
|
@netflix.name.must_equal 'Netflix'
|
15
16
|
end
|
16
17
|
|
17
|
-
it 'make blank account' do
|
18
|
+
it 'should make blank account' do
|
18
19
|
@a.wont_be_nil
|
19
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
|
20
26
|
end
|
21
27
|
|
22
28
|
describe '#save' do
|
@@ -32,8 +38,7 @@ describe RIQ::Account do
|
|
32
38
|
describe "#field_value" do
|
33
39
|
it 'should fetch a field value' do
|
34
40
|
@netflix.field_value(2).wont_be_nil
|
41
|
+
@dat.field_value(0).wont_be_nil
|
35
42
|
end
|
36
43
|
end
|
37
|
-
|
38
|
-
# TODO: get all accounts
|
39
44
|
end
|
data/test/test_batch_manager.rb
CHANGED
@@ -12,6 +12,7 @@ describe RIQ::BatchManager do
|
|
12
12
|
accounts = RIQ.accounts
|
13
13
|
accounts.each do |a|
|
14
14
|
a.id.wont_be_nil
|
15
|
+
a.name.wont_be_nil
|
15
16
|
@c += 1
|
16
17
|
break if @c >= 20
|
17
18
|
end
|
@@ -36,10 +37,36 @@ describe RIQ::BatchManager do
|
|
36
37
|
lists = RIQ.lists
|
37
38
|
lists.each do |l|
|
38
39
|
l.id.wont_be_nil
|
40
|
+
l.title.wont_be_nil
|
41
|
+
l.fields.wont_be_nil
|
39
42
|
@c += 1
|
43
|
+
lic = 0
|
44
|
+
l.list_items.each do |li|
|
45
|
+
lic += 1
|
46
|
+
break if lic >= 5
|
47
|
+
end
|
48
|
+
lic.wont_equal 0
|
40
49
|
break if @c >= 20
|
41
50
|
end
|
42
51
|
@c.wont_equal 0
|
43
52
|
end
|
44
53
|
end
|
54
|
+
|
55
|
+
describe '#first' do
|
56
|
+
it 'should get one contact' do
|
57
|
+
c = nil
|
58
|
+
c = RIQ.contacts.first
|
59
|
+
c.must_be_instance_of RIQ::Contact
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# describe '#fetch_options' do
|
64
|
+
# it 'should respect limits' do
|
65
|
+
# b = RIQ.contacts(opts: {_limit: 3})
|
66
|
+
# b.each do |i|
|
67
|
+
# @c += 1
|
68
|
+
# end
|
69
|
+
# @c.must_equal 3
|
70
|
+
# end
|
71
|
+
# end
|
45
72
|
end
|
data/test/test_contact.rb
CHANGED
@@ -7,6 +7,7 @@ describe RIQ::Contact do
|
|
7
7
|
# sammy's contact ID
|
8
8
|
@sammy = RIQ.contact('542b205be4b04cd81270dff9')
|
9
9
|
@c = RIQ.contact
|
10
|
+
@dat = RIQ.contact({properties: {'name' => ['david'], email: ['dab@relateiq.com']}})
|
10
11
|
end
|
11
12
|
|
12
13
|
describe '#new' do
|
@@ -22,7 +23,6 @@ describe RIQ::Contact do
|
|
22
23
|
describe '#save' do
|
23
24
|
it 'should create new contact and delete it' do
|
24
25
|
@c.add(:name, 'Ron Mexico')
|
25
|
-
# @c.field_value(2, '1')
|
26
26
|
@c.save
|
27
27
|
|
28
28
|
@c.id.wont_be_nil
|
@@ -37,6 +37,18 @@ describe RIQ::Contact do
|
|
37
37
|
|
38
38
|
@sammy.email.wont_equal @sammy.add(:email, 'jammari@stanford.edu')
|
39
39
|
end
|
40
|
+
|
41
|
+
it 'should only take strings as properties' do
|
42
|
+
@c.add(:phone, '867-5309').wont_be_empty
|
43
|
+
|
44
|
+
begin
|
45
|
+
@c.add(:name, {value: 'Jenny'})
|
46
|
+
rescue RIQ::RIQError
|
47
|
+
nil.must_be_nil
|
48
|
+
else
|
49
|
+
1.must_be_nil
|
50
|
+
end
|
51
|
+
end
|
40
52
|
end
|
41
53
|
|
42
54
|
describe '#upsert' do
|
data/test/test_event.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../lib/riq'
|
3
|
+
|
4
|
+
describe RIQ::Event do
|
5
|
+
before do
|
6
|
+
RIQ.init
|
7
|
+
# sammy's contact ID
|
8
|
+
@e = RIQ.event
|
9
|
+
@ev = RIQ.event({subject: "My Sub", body: "Very intersting body", 'participantIds' => [{type: :email, value: 'fake@fakerelateiq.com'}]})
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#new' do
|
13
|
+
it 'should start blank' do
|
14
|
+
@e.subject.must_be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should take a hash' do
|
18
|
+
@ev.subject.wont_be_nil
|
19
|
+
@ev.participant_ids.wont_be_empty
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#save' do
|
24
|
+
it 'should fail without subject'do
|
25
|
+
begin
|
26
|
+
@e.save
|
27
|
+
rescue RIQ::HTTPError
|
28
|
+
nil.must_be_nil
|
29
|
+
else
|
30
|
+
1.must_be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should save with data' do
|
35
|
+
@ev.save.must_be_kind_of Hash
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#add_participant' do
|
40
|
+
it 'should add a participant' do
|
41
|
+
p = {type: :email, value: 'good'}
|
42
|
+
@e.add_participant(p[:type], p[:value])
|
43
|
+
@e.participant_ids.must_include p
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should reject bad types' do
|
47
|
+
begin
|
48
|
+
@e.add_participant(:blarg, 'bad type')
|
49
|
+
rescue RIQ::RIQError
|
50
|
+
nil.must_be_nil
|
51
|
+
else
|
52
|
+
1.must_be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../lib/riq'
|
3
|
+
|
4
|
+
describe RIQ::ListItem do
|
5
|
+
before do
|
6
|
+
RIQ.init
|
7
|
+
lid = '54ca9b25e4b0b29d80ce4b4e'
|
8
|
+
@l = RIQ.list(lid)
|
9
|
+
@li = @l.list_items.first
|
10
|
+
@blank = @l.list_item
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#field_value' do
|
14
|
+
it 'should return a value' do
|
15
|
+
@li.field_value(0).wont_be_nil
|
16
|
+
@blank.field_value(0).must_be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#save' do
|
21
|
+
it 'should create and delete' do
|
22
|
+
@blank.field_value(0, 1)
|
23
|
+
@blank.contact_ids << RIQ.contacts.first.id
|
24
|
+
@blank.save
|
25
|
+
@blank.id.wont_be_nil
|
26
|
+
|
27
|
+
assert(@blank.delete)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should update' do
|
31
|
+
start = @li.field_value(0)
|
32
|
+
if start == '1'
|
33
|
+
@li.field_value(0, 0)
|
34
|
+
else
|
35
|
+
@li.field_value(0, 1)
|
36
|
+
end
|
37
|
+
@li.save
|
38
|
+
|
39
|
+
@li.field_value(0).wont_equal start
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Brownman
|
@@ -58,8 +58,8 @@ files:
|
|
58
58
|
- lib/riq/error.rb
|
59
59
|
- lib/riq/event.rb
|
60
60
|
- lib/riq/list.rb
|
61
|
+
- lib/riq/list_item.rb
|
61
62
|
- lib/riq/list_item_manager.rb
|
62
|
-
- lib/riq/listitem.rb
|
63
63
|
- lib/riq/riq_obj.rb
|
64
64
|
- lib/riq/user.rb
|
65
65
|
- riq.gemspec
|
@@ -67,6 +67,8 @@ files:
|
|
67
67
|
- test/test_account.rb
|
68
68
|
- test/test_batch_manager.rb
|
69
69
|
- test/test_contact.rb
|
70
|
+
- test/test_event.rb
|
71
|
+
- test/test_list_item.rb
|
70
72
|
homepage: https://github.com/relateiq/ruby-sdk
|
71
73
|
licenses:
|
72
74
|
- MIT
|
@@ -79,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
81
|
requirements:
|
80
82
|
- - ">="
|
81
83
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
84
|
+
version: 2.0.0
|
83
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
86
|
requirements:
|
85
87
|
- - ">="
|
@@ -87,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
89
|
version: '0'
|
88
90
|
requirements: []
|
89
91
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.2.2
|
91
93
|
signing_key:
|
92
94
|
specification_version: 4
|
93
95
|
summary: Ruby RIQ API client
|
@@ -96,4 +98,6 @@ test_files:
|
|
96
98
|
- test/test_account.rb
|
97
99
|
- test/test_batch_manager.rb
|
98
100
|
- test/test_contact.rb
|
101
|
+
- test/test_event.rb
|
102
|
+
- test/test_list_item.rb
|
99
103
|
has_rdoc:
|