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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 298db01f6539c6549b61843f84e90c13e3392c44
4
- data.tar.gz: cf5dd577bd23f093e1112504a7713ced7da69e73
3
+ metadata.gz: 2e861c8df701fcf3bc680f3061da48295ab332d2
4
+ data.tar.gz: 27ab3509e83f59d86fd018b0a6f9f852812d8e75
5
5
  SHA512:
6
- metadata.gz: b491d52bd9c27e4c6f9873b24888d4037492b4e20cf90fb9e005b82642caf0003deccc7b017b4971dd48905dcbeedb47adf776d553b60f8def3046ad740d87f2
7
- data.tar.gz: 7ecd4d753690f5d1661357a65bf49490a0d09fd1592067df167bce4f833ec25297551658b37de7f467801ce80d2e64e5fe8288d53b3dea8b254c08e7d04d3c01
6
+ metadata.gz: 1f5c66f3151336e1e93d6e56170a7aaedabf1c1140fb8b888f0a421952d247c2e2863004d3f5766e33c72e4d06d84dbe743179e26447fe11e1edb91ac591fa08
7
+ data.tar.gz: 240b0c53d2bae6c5ed73a169721cef3b51bf72e27ddf15e5e68ca48d1940e107a429cce1a959e111901e65baf8cb439c343caa9b810b09870ae544e65df30fd7
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Brownman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-15 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -44,31 +44,7 @@ email:
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
- files:
48
- - ".gitignore"
49
- - ".yardopts"
50
- - Gemfile
51
- - LICENSE.txt
52
- - README.md
53
- - lib/riq.rb
54
- - lib/riq/account.rb
55
- - lib/riq/batch_manager.rb
56
- - lib/riq/client.rb
57
- - lib/riq/contact.rb
58
- - lib/riq/error.rb
59
- - lib/riq/event.rb
60
- - lib/riq/list.rb
61
- - lib/riq/list_item.rb
62
- - lib/riq/list_item_manager.rb
63
- - lib/riq/riq_obj.rb
64
- - lib/riq/user.rb
65
- - riq.gemspec
66
- - test/test.rb
67
- - test/test_account.rb
68
- - test/test_batch_manager.rb
69
- - test/test_contact.rb
70
- - test/test_event.rb
71
- - test/test_list_item.rb
47
+ files: []
72
48
  homepage: https://github.com/relateiq/ruby-sdk
73
49
  licenses:
74
50
  - MIT
@@ -93,11 +69,5 @@ rubygems_version: 2.2.2
93
69
  signing_key:
94
70
  specification_version: 4
95
71
  summary: Ruby RIQ API client
96
- test_files:
97
- - test/test.rb
98
- - test/test_account.rb
99
- - test/test_batch_manager.rb
100
- - test/test_contact.rb
101
- - test/test_event.rb
102
- - test/test_list_item.rb
72
+ test_files: []
103
73
  has_rdoc:
data/.gitignore DELETED
@@ -1,42 +0,0 @@
1
- # Created by https://www.gitignore.io
2
-
3
- ### Ruby ###
4
- *.gem
5
- *.rbc
6
- /.config
7
- /coverage/
8
- /InstalledFiles
9
- /pkg/
10
- /spec/reports/
11
- /test/tmp/
12
- /test/version_tmp/
13
- /tmp/
14
-
15
- ## Specific to RubyMotion:
16
- .dat*
17
- .repl_history
18
- build/
19
-
20
- ## Documentation cache and generated files:
21
- /.yardoc/
22
- /_yardoc/
23
- /doc/
24
- /rdoc/
25
- Gemfile.lock
26
-
27
- ## Environment normalisation:
28
- /.bundle/
29
- /vendor/bundle
30
- /lib/bundler/man/
31
-
32
- # for a library or gem, you might want to ignore these files since the code is
33
- # intended to run in multiple environments; otherwise, check them in:
34
- # Gemfile.lock
35
- # .ruby-version
36
- # .ruby-gemset
37
-
38
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
39
- .rvmrc
40
-
41
- # test file
42
- t.rb
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- lib/**/*.rb
2
- --title RelateIQ
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- group :development do
5
- gem 'pry'
6
- end
7
-
8
- gem 'httparty', '0.13.3'
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 RelateIQ
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,15 +0,0 @@
1
- # RelateIQ Ruby SDK
2
-
3
- A full featured API interface for interacting with the [RelateIQ](https://relateiq.com) API.
4
-
5
- ## Overview
6
-
7
- <!--[![Gem Version](https://badge.fury.io/rb/riq.svg)](http://badge.fury.io/rb/riq)-->
8
- [![Gem Version](https://img.shields.io/gem/v/riq.svg)](http://badge.fury.io/rb/riq)
9
- <!--[![MIT license](http://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)-->
10
-
11
-
12
- ## Helpful Links
13
-
14
- * [Full ruby docs](http://www.rubydoc.info/gems/riq)
15
- * [Examples and API docs](https://api.relateiq.com/#/ruby)
data/lib/riq.rb DELETED
@@ -1,103 +0,0 @@
1
- # The namespace from which all magic springs
2
- module RIQ
3
- # Could fetch defaults or something here
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 }
@@ -1,82 +0,0 @@
1
- require_relative 'riq_obj'
2
- using RIQExtensions
3
-
4
- module RIQ
5
- # Accounts represent companies (or other entities).
6
- class Account < RIQObject
7
- attr_accessor :name
8
- attr_accessor :field_values
9
-
10
- # (see RIQObject#node)
11
- def node
12
- "accounts/#{@id}"
13
- end
14
-
15
- # (see #node)
16
- def self.node(arg = nil)
17
- "accounts"
18
- end
19
-
20
- # (see RIQObject#data)
21
- def data
22
- {
23
- id: @id,
24
- name: @name,
25
- field_values: @field_values
26
- }
27
- end
28
-
29
- # (see RIQObject#payload)
30
- def payload
31
- # TODO: find more elegant way to do this
32
- pld = data
33
- pld['fieldValues'] = @field_values.to_raw
34
- pld.delete(:field_values)
35
- pld.to_json
36
- end
37
-
38
- # @overload field_value(key)
39
- # @param key [String, Integer]
40
- # @return [Array] Value of key
41
- # @overload field_value(key, value)
42
- # Sets key to value
43
- # @param key [String, Integer] Key to set
44
- # @param value [#to_s] Sets key to value
45
- def field_value(key, value = nil)
46
- # TODO: double check that this works with arrays of stuff
47
- # or, have a format function that casts ints to string on save
48
- if value.nil?
49
- @field_values.fetch(key.to_sym, nil)
50
- else
51
- @field_values[key.to_sym] = value.to_s
52
- {key.to_sym => value.to_s}
53
- end
54
- end
55
-
56
- private
57
- def init(obj = nil)
58
- unless obj.nil?
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]
63
- else
64
- @id = nil
65
- @name = nil
66
- @field_values = {}
67
- end
68
- self
69
- end
70
-
71
- end
72
-
73
- class << self
74
- # Convenince method to create new Accounts
75
- # @param id [String, nil] create a blank Account object or
76
- # fetch an existing one by id.
77
- # @return [Account]
78
- def account(id = nil)
79
- Account.new(id)
80
- end
81
- end
82
- end
@@ -1,197 +0,0 @@
1
- using RIQExtensions
2
-
3
- module RIQ
4
- # Manages caching and fetching for a certain type of child object.
5
- class BatchManager
6
- # @return [Hash] current fetch options
7
- attr_reader :fetch_options
8
-
9
- # @param klass [RIQObject] The child class that's being fetched, such as {Account} or {List}
10
- # @param page_length [Integer] The number of items per page
11
- # @param opts [Hash] fetch options
12
- def initialize(klass, page_length = 200, opts: {})
13
- @klass = klass
14
- begin
15
- raise unless @klass.ancestors.include? RIQ::RIQObject
16
- rescue
17
- raise RIQError, 'Must pass a RIQ Class'
18
- end
19
-
20
- reset_cache
21
- # ruby says that nil is an argument and page_size was getting set to 0
22
- @page_length = page_length.nil? ? 200 : page_length
23
- self.send(:fetch_options=, opts)
24
- @client = RIQ.client
25
- end
26
-
27
- # Iterator for each item in the manager. Pass a block to it!
28
- # @example
29
- # RIQ.lists.each do |l|
30
- # puts l
31
- # end
32
- def each(&blok)
33
- reset_cache
34
- loop do
35
- x = next_item
36
- if x
37
- blok.call(x)
38
- else
39
- return
40
- end
41
- end
42
- end
43
-
44
- # Returns the first child object, mainly used for testing
45
- # @return [RIQObject]
46
- def first
47
- reset_cache
48
- fetch_page(0, 1).first
49
- end
50
-
51
- # Set fetch options
52
- # @param opts [Hash] Where values are either strings or arrays
53
- def fetch_options=(opts = {})
54
- reset_cache
55
- options = {}
56
- opts.each do |k, v|
57
- # some args are comma-separated arrays, some are just args
58
- if v.is_a? Array
59
- options[k] = v.join(',')
60
- else
61
- options[k] = v
62
- end
63
- end
64
- @fetch_options = options#.to_cam
65
- end
66
-
67
- private
68
- def next_item
69
- # I believe this is resetting opts somehow/not respecting limit
70
- if @cache_index == @cache.size
71
- return nil if ![0, @page_length].include? @cache.size
72
- # puts "\n=== fetching page! (#{@page_index}) (#{@page_length})"
73
- @cache = fetch_page(@page_index, @page_length)
74
- @page_index += @cache.size
75
- @cache_index = 0
76
- end
77
-
78
- if @cache_index < @cache.size
79
- obj = @cache[@cache_index]
80
- @cache_index += 1
81
- obj
82
- else
83
- nil
84
- end
85
- end
86
-
87
- # def fetch_batch(param, values, max_size)
88
- # objects = []
89
- # chunks = []
90
- # (0...values.size).step(max_size) do |i|
91
- # chunks << values[i...i+max_size]
92
- # end
93
- # chunks.each_with_index do |obj, i|
94
- # begin
95
- # set_fetch_options({param: chunk.join(',')})
96
- # objects << fetch_page
97
- # rescue HTTPError => e
98
- # # max url length is 8192 (2^13). If longer, will give a 414 error.
99
- # if [413, 414].include? e.code
100
- # objects << fetch_batch(param, chunk, (max_size/2.0).ceil)
101
- # else
102
- # # raise a certain error?
103
- # raise e
104
- # end
105
- # end
106
- # end
107
- # objects
108
- # end
109
-
110
- def fetch_page(index = 0, limit = nil)
111
- limit = @page_length if limit.nil?
112
-
113
- @fetch_options[:_start] = index
114
- @fetch_options[:_limit] = limit
115
-
116
- # all class#node functions can take an arg, so far, only list items need it.
117
- # having list_id usually be nil (that is, undefined) is fine. probably.
118
- data = @client.get(@klass.node(@list_id), options: @fetch_options)
119
-
120
- objects = []
121
- data.fetch('objects', []).each do |obj|
122
- objects << @klass.new(obj)
123
- end
124
- objects
125
- end
126
-
127
- def reset_cache
128
- # shouldn't reset options, that's silly
129
- # @fetch_options = {}
130
- @cache = []
131
- @cache_index = 0
132
- @page_index = 0
133
- end
134
-
135
- # these used to be 2 methods, now they're one
136
- # not that we ever seem to use them, but they're there
137
- def batch(objs, mode)
138
- return_objs = {}
139
- while objs.size > 0
140
- chunk_size = objs.size > @page_length ? @page_length : objs.size
141
- chunk = objs[0...chunk_size]
142
- objs = chunk_size < objs.size ? objs[chunk_size..-1] : []
143
-
144
- batch_objs = batch_helper(mode, chunk)
145
- return_objs['success_objects'] = batch_objs.fetch('success_objects', [])
146
- return_objs['error_objects'] = batch_objs.fetch('error_objects', [])
147
- end
148
- return_objs
149
- end
150
-
151
- def batch_helper(mode, objs)
152
- payloads = []
153
- objs.each {|o| payloads << o.payload}
154
-
155
- if mode == :create
156
- batch_results = @client.post('/createBatch', {objects: payloads})
157
- elsif mode == :update
158
- batch_results = @client.put('/updateBatch', {objects: payloads})
159
- else
160
- raise RIQError, 'Invalid Batch Mode'
161
- end
162
-
163
- batch_results['success_objects'] = []
164
- batch_results['successObjects'].each do |o|
165
- batch_results['success_objects'] << self.class(o)
166
- end
167
-
168
- batch_results['error_objects'] = []
169
- batch_results['errorObjects'].each do |o|
170
- batch_results['error_objects'] << self.class(o)
171
- end
172
-
173
- batch_results
174
- end
175
- end
176
-
177
- class << self
178
- # @!macro [new] conv
179
- # Returns an iterator for all $0
180
- # @return [BatchManager]
181
-
182
- # @macro conv
183
- def lists(page_size = nil)
184
- BatchManager.new(RIQ::List, page_size)
185
- end
186
-
187
- # @macro conv
188
- def contacts(page_size = nil)
189
- BatchManager.new(RIQ::Contact, page_size)
190
- end
191
-
192
- # @macro conv
193
- def accounts(page_size = nil)
194
- BatchManager.new(RIQ::Account, page_size)
195
- end
196
- end
197
- end