riq 0.8.3

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.
@@ -0,0 +1,142 @@
1
+ # the objcet from which accounts, lists, items, etc will inherit
2
+
3
+ require 'pp'
4
+ require 'json'
5
+ require_relative 'client'
6
+
7
+
8
+ module RIQ
9
+ # @abstract This class should not be used directly.
10
+ # Instead, use a child such as {Contact} or {Account}.
11
+ class RIQObject
12
+ attr_accessor :id
13
+ # attr_reader :modified_date
14
+
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.fetch(node)
26
+ end
27
+ init(data)
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
+ # @return [Hash] all relevant stored data
40
+ def data
41
+ raise RIQError, 'This should be overwritten'
42
+ end
43
+
44
+ # @return [String] the json representation of {#data}
45
+ def payload
46
+ data.to_json
47
+ end
48
+
49
+ # Creates or updates the object
50
+ def save(options = nil)
51
+ if @id.nil?
52
+ # create
53
+ init(@client.post(node, payload, options: options))
54
+ else
55
+ # update
56
+ init(@client.put(node, payload, options: options))
57
+ end
58
+ end
59
+
60
+ def delete
61
+ @client.delete(node)
62
+ end
63
+
64
+ # when you print the object
65
+ # def to_s
66
+ # JSON.pretty_generate(data)
67
+ # data
68
+ # end
69
+
70
+ # When the object itself is called or returned
71
+ def inspect
72
+ data
73
+ end
74
+
75
+ private
76
+ def init
77
+ raise RIQError, 'This should be overwritten'
78
+ end
79
+
80
+ # Converts to RIQ API's [{raw: "VALUE"}] format
81
+ def to_raw(hsh)
82
+ return {} if hsh.empty?
83
+ obj = {}
84
+ hsh.each do |k, v|
85
+ obj[k] = [{raw: v}]
86
+ end
87
+ obj
88
+ end
89
+
90
+ # Converts from RIQ API's [{raw: "VALUE"}] format
91
+ def from_raw(hsh)
92
+ return {} if hsh.empty?
93
+ obj = {}
94
+ hsh.each do |k,v|
95
+ obj[k] = v.first['raw']
96
+ end
97
+ obj
98
+ end
99
+
100
+ def camel_case(sym)
101
+ temp = sym.to_s.split('_').map(&:capitalize).join
102
+ temp[0].downcase + temp[1..-1]
103
+ end
104
+
105
+ # make everything a symbol
106
+ def symbolize(h)
107
+ return h unless h.respond_to? :keys
108
+
109
+ obj = {}
110
+ h.each do |k, v|
111
+ if v.respond_to? :keys
112
+ obj[k.to_sym] = symbolize(v)
113
+ else
114
+ if v.respond_to? :each
115
+ v.map! do |i|
116
+ symbolize(i)
117
+ end
118
+ end
119
+ obj[k.to_sym] = v
120
+ end
121
+ end
122
+ obj
123
+ end
124
+
125
+ # def exists
126
+ # if @id.nil?
127
+ # false
128
+ # else
129
+ # @client.fetch(node)
130
+ # end
131
+ # end
132
+
133
+ end
134
+
135
+ # Monkeypatches
136
+ # class Symbol
137
+ # def camel_case
138
+ # temp = self.to_s.split('_').map(&:capitalize).join
139
+ # temp[0].downcase + temp[1..-1]
140
+ # end
141
+ # end
142
+ end
@@ -0,0 +1,36 @@
1
+ # users are things
2
+
3
+ module RIQ
4
+ class User < RIQObject
5
+ attr_accessor :name
6
+ attr_accessor :email
7
+
8
+ # (see RIQObject#node)
9
+ def node
10
+ "users/#{@id}"
11
+ end
12
+
13
+ # (see RIQObject#data)
14
+ def data
15
+ {
16
+ id: @id,
17
+ name: @name,
18
+ email: @email
19
+ }
20
+ end
21
+
22
+ private
23
+ def init(obj = nil)
24
+ unless obj.nil?
25
+ @id = obj['id']
26
+ @name = obj['name']
27
+ @email = obj['email']
28
+ else
29
+ @id = nil
30
+ @name = nil
31
+ @email = nil
32
+ end
33
+ self
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ # testing!
2
+
3
+ # require everything to run all tests
4
+ Dir["#{File.dirname(__FILE__)}/*.rb"].each{|file| require_relative file.split('/').last}
@@ -0,0 +1,39 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/relateiq'
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
+ end
11
+
12
+ describe '#new' do
13
+ it 'should get account' do
14
+ @netflix.name.must_equal 'Netflix'
15
+ end
16
+
17
+ it 'make blank account' do
18
+ @a.wont_be_nil
19
+ end
20
+ end
21
+
22
+ describe '#save' do
23
+ it 'should create new account' do
24
+ @a.name = 'Delete Test Inc'
25
+ @a.field_value(2, '1')
26
+ @a.save
27
+
28
+ @a.id.wont_be_nil
29
+ end
30
+ end
31
+
32
+ describe "#field_value" do
33
+ it 'should fetch a field value' do
34
+ @netflix.field_value(2).wont_be_nil
35
+ end
36
+ end
37
+
38
+ # TODO: get all accounts
39
+ end
@@ -0,0 +1,45 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/relateiq'
3
+
4
+ describe RIQ::BatchManager do
5
+ before do
6
+ RIQ.init
7
+ @c = 0
8
+ end
9
+
10
+ describe '#accounts' do
11
+ it 'should get all accounts' do
12
+ accounts = RIQ.accounts
13
+ accounts.each do |a|
14
+ a.id.wont_be_nil
15
+ @c += 1
16
+ break if @c >= 20
17
+ end
18
+ @c.wont_equal 0
19
+ end
20
+ end
21
+
22
+ describe '#contacts' do
23
+ it 'should get all contacts' do
24
+ contacts = RIQ.contacts
25
+ contacts.each do |con|
26
+ con.id.wont_be_nil
27
+ @c += 1
28
+ break if @c >= 20
29
+ end
30
+ @c.wont_equal 0
31
+ end
32
+ end
33
+
34
+ describe '#lists' do
35
+ it 'should get all lists' do
36
+ lists = RIQ.lists
37
+ lists.each do |l|
38
+ l.id.wont_be_nil
39
+ @c += 1
40
+ break if @c >= 20
41
+ end
42
+ @c.wont_equal 0
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,50 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/relateiq'
3
+
4
+ describe RIQ::Contact do
5
+ before do
6
+ RIQ.init
7
+ # sammy's contact ID
8
+ @sammy = RIQ.contact('542b205be4b04cd81270dff9')
9
+ @c = RIQ.contact
10
+ end
11
+
12
+ describe '#new' do
13
+ it 'should get account' do
14
+ @sammy.name.must_include 'Sammy Nammari'
15
+ end
16
+
17
+ it 'make blank contact' do
18
+ @c.wont_be_nil
19
+ end
20
+ end
21
+
22
+ describe '#save' do
23
+ it 'should create new contact and delete it' do
24
+ @c.add(:name, 'Ron Mexico')
25
+ # @c.field_value(2, '1')
26
+ @c.save
27
+
28
+ @c.id.wont_be_nil
29
+
30
+ assert(@c.delete)
31
+ end
32
+ end
33
+
34
+ describe 'properties' do
35
+ it 'should add new emails only if they\'re new' do
36
+ @sammy.email.must_equal @sammy.add(:email, 'nammari@stanford.edu')
37
+
38
+ @sammy.email.wont_equal @sammy.add(:email, 'jammari@stanford.edu')
39
+ end
40
+ end
41
+
42
+ describe '#upsert' do
43
+ it 'should upsert' do
44
+ # this could be better
45
+ @sammy.email.must_equal @sammy.upsert.email
46
+
47
+ # should add another assertion with the blank contact
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.3
5
+ platform: ruby
6
+ authors:
7
+ - David Brownman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ description: Full featured ruby client for interacting with the RelateIQ API
42
+ email:
43
+ - david@relateiq.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".yardopts"
50
+ - Gemfile
51
+ - lib/relateiq.rb
52
+ - lib/relateiq/account.rb
53
+ - lib/relateiq/batch_manager.rb
54
+ - lib/relateiq/client.rb
55
+ - lib/relateiq/contact.rb
56
+ - lib/relateiq/error.rb
57
+ - lib/relateiq/events.rb
58
+ - lib/relateiq/list.rb
59
+ - lib/relateiq/list_item_manager.rb
60
+ - lib/relateiq/listitem.rb
61
+ - lib/relateiq/riq_obj.rb
62
+ - lib/relateiq/user.rb
63
+ - test/test.rb
64
+ - test/test_account.rb
65
+ - test/test_batch_manager.rb
66
+ - test/test_contact.rb
67
+ homepage: https://github.com/relateiq/ruby-sdk
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.9.3
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.2.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Ruby RIQ API client
91
+ test_files:
92
+ - test/test.rb
93
+ - test/test_account.rb
94
+ - test/test_batch_manager.rb
95
+ - test/test_contact.rb
96
+ has_rdoc: