highrise_wrapper 0.0.2 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +57 -1
- data/TODO +5 -5
- data/highrise_wrapper.gemspec +6 -4
- data/lib/highrise_wrapper.rb +2 -1
- data/lib/highrise_wrapper/contact.rb +39 -10
- data/lib/highrise_wrapper/version.rb +2 -2
- data/mytests.rb +193 -53
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2RkZWQ4M2U3YWRjMTg1NzcwMGZkNTZjZjg5NjJjNzUwM2VhMzBmNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2JhMGZiYzBmNmM0MzYxMzVkMDI4YTYxOWE5ZDVhMjU3MmU4MmI4OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWJiNDk5YTcyNTVlY2Q3NzcyOWM3ZjI5ZDY5YjAxZWI4ZWRhMTE0MzE0N2Y0
|
10
|
+
NGRjNmZkNTJlNTBkM2JhYzA2NTAxMmI0MzdmMGZhODFkNjUwMjI3ZDRhODUw
|
11
|
+
ZmNjZTQ3NzBmNDdkMmZhZjI3MmQ0YTViMmM3OWI2NGQwZmQ2Y2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmNkZjIxNDc4NDVjOWQwYTVhMzVjMjZlYWRlMjM3ZGJjM2EyN2Y5ZWM3MjVm
|
14
|
+
MGM4M2FmZGE0NDA4MDRjMGU0NTE1ZTEzYWRlOTc1YjI5MjY0OThlOWZiMTI1
|
15
|
+
YWQ4NzBiNzE1NGZjN2UyZGE0ZWZmNGRkZGUyYmUyNDUxZDY4MWI=
|
data/README.md
CHANGED
@@ -19,7 +19,63 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
-
|
22
|
+
You can start to use with just a few steps. All you need is to
|
23
|
+
have a class including our `Contact` module that:
|
24
|
+
|
25
|
+
- implements a `highrise_hash` method that returns a hash with the contact information using the format the highrise_api ( https://github.com/basecamp/highrise-api ) uses
|
26
|
+
- has `highrise_token` and `highrise_base_url` available
|
27
|
+
|
28
|
+
### Example code
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
class Contact < ActiveRecord::Base
|
32
|
+
include HighriseWrapper::ActiveRecord
|
33
|
+
|
34
|
+
belongs_to :company
|
35
|
+
|
36
|
+
def fullname
|
37
|
+
"#{first_name} #{last_name}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def highrise_hash
|
41
|
+
{
|
42
|
+
'first_name' => first_name,
|
43
|
+
'last_name' => last_name,
|
44
|
+
'title' => job_title,
|
45
|
+
'company_name' => company_name,
|
46
|
+
'contact_data' => {
|
47
|
+
'email_addresses' => [{
|
48
|
+
'address' => email,
|
49
|
+
'location' => 'Work'
|
50
|
+
}],
|
51
|
+
'phone_numbers' => [{
|
52
|
+
'number' => phone,
|
53
|
+
'location' => 'Work'
|
54
|
+
}],
|
55
|
+
'web_addresses' => [{
|
56
|
+
'location' => 'Work',
|
57
|
+
'url' => website
|
58
|
+
}]
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def highrise_token
|
64
|
+
company.highrise_token
|
65
|
+
end
|
66
|
+
|
67
|
+
def highrise_base_url
|
68
|
+
company.highrise_base_url
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
### Sample app
|
74
|
+
|
75
|
+
There is an example application you can take a look at:
|
76
|
+
|
77
|
+
- Source: http://github.com/rhlobo/loboapp
|
78
|
+
- Demo: http://loboapp.herokuapp.com
|
23
79
|
|
24
80
|
## Contributing
|
25
81
|
|
data/TODO
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
MAIN SCOPE:
|
2
2
|
✔ Test integration (highrise gem usage) @done (14-03-20 16:32)
|
3
3
|
✔ Make project read to implementation @done (14-03-20 16:36)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
✔ Experiment with conversion methods @done (14-04-02 18:05)
|
5
|
+
✔ Criar metodo de conexão com highrise @done (14-04-02 18:05)
|
6
|
+
✔ Cadastramento de um contato @done (14-04-02 18:06)
|
7
|
+
✔ Descadastramento de um contato @done (14-04-02 18:06)
|
8
|
+
✘ Fazer com que chamada a api seja assincrona (outra thread, ou etc) @cancelled (14-04-02 18:06)
|
9
9
|
☐ Remover script de testes
|
10
10
|
|
11
11
|
DOCUMENTATION:
|
data/highrise_wrapper.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'highrise_wrapper/version'
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = "highrise_wrapper"
|
9
|
-
spec.version =
|
9
|
+
spec.version = HighriseWrapper::VERSION
|
10
10
|
spec.authors = ["rhlobo"]
|
11
11
|
spec.email = ["rhlobo+github@gmail.com"]
|
12
12
|
spec.summary = "Gem to provide easy usage of Highrise API"
|
@@ -25,8 +25,10 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.5"
|
28
|
-
spec.add_development_dependency "rake"
|
29
|
-
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "rake", "~> 0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 0"
|
30
30
|
|
31
|
-
spec.add_dependency "highrise", "~>3.1"
|
31
|
+
spec.add_dependency "highrise", "~> 3.1.0"
|
32
|
+
#spec.add_dependency "simple_attribute_mapper", "~> 0.0"
|
33
|
+
#spec.add_dependency "virtus", "~> 1.0"
|
32
34
|
end
|
data/lib/highrise_wrapper.rb
CHANGED
@@ -1,19 +1,48 @@
|
|
1
|
-
module
|
1
|
+
module HighriseWrapper
|
2
|
+
module ActiveRecord
|
3
|
+
def on_highrise?
|
4
|
+
!self.highrise_id.nil?
|
5
|
+
end
|
2
6
|
|
3
|
-
module InstanceMethods
|
4
7
|
def highrise_save
|
5
|
-
|
6
|
-
|
8
|
+
logger.info 'Saving #{fullname} to highrise'
|
9
|
+
|
10
|
+
begin
|
11
|
+
setup_highrise
|
12
|
+
person = Highrise::Person.new(self.highrise_hash)
|
13
|
+
person.save!
|
14
|
+
self.highrise_id = person.attributes['id']
|
15
|
+
self.save!
|
16
|
+
rescue Exception => exception
|
17
|
+
logger.error(
|
18
|
+
"It was not possible to save contact to highrise: " +
|
19
|
+
"#{exception.class} (#{exception.message})")
|
20
|
+
return false
|
21
|
+
end
|
7
22
|
end
|
8
23
|
|
9
24
|
def highrise_remove
|
10
|
-
|
11
|
-
sleep(10.seconds)
|
12
|
-
end
|
25
|
+
logger.info 'Removing #{fullname} from highrise'
|
13
26
|
|
14
|
-
|
15
|
-
|
27
|
+
begin
|
28
|
+
setup_highrise
|
29
|
+
person = Highrise::Person.find(highrise_id)
|
30
|
+
person.destroy
|
31
|
+
self.highrise_id = nil
|
32
|
+
self.save!
|
33
|
+
rescue Exception => exception
|
34
|
+
logger.error(
|
35
|
+
"It was not possible to remove contact from highrise: " +
|
36
|
+
"#{exception.class} (#{exception.message})")
|
37
|
+
return false
|
16
38
|
end
|
17
|
-
|
39
|
+
end
|
18
40
|
|
41
|
+
private
|
42
|
+
def setup_highrise
|
43
|
+
Highrise::Base.site = self.highrise_base_url
|
44
|
+
Highrise::Base.user = self.highrise_token
|
45
|
+
Highrise::Base.format = :xml
|
46
|
+
end
|
47
|
+
end
|
19
48
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.0.
|
1
|
+
module HighriseWrapper
|
2
|
+
VERSION = "0.0.9"
|
3
3
|
end
|
data/mytests.rb
CHANGED
@@ -1,74 +1,214 @@
|
|
1
|
+
|
1
2
|
require 'highrise'
|
3
|
+
require 'highrise_wrapper'
|
4
|
+
|
5
|
+
require 'virtus'
|
6
|
+
require 'simple_attribute_mapper'
|
2
7
|
|
8
|
+
|
9
|
+
########### highrise setup
|
3
10
|
Highrise::Base.site = 'https://personal1788.highrisehq.com'
|
4
11
|
Highrise::Base.user = 'ee54dd83345c800c14b6fda0a650659e'
|
5
12
|
Highrise::Base.format = :xml
|
6
13
|
|
7
14
|
#@people = Highrise::Person.find_all_across_pages(:params => {:tag_id => 12345})
|
8
|
-
|
15
|
+
#@people = Highrise::Person.find_all_across_pages
|
9
16
|
|
10
17
|
# [#<Highrise::Person:0x9db1d80 @attributes={"author_id"=>1018065, "background"=>nil, "company_id"=>nil, "created_at"=>2014-03-17 22:11:22 UTC, "first_name"=>"A", "group_id"=>nil, "id"=>201374388, "last_name"=>"A", "owner_id"=>nil, "title"=>nil, "updated_at"=>2014-03-17 22:11:22 UTC, "visible_to"=>"Everyone", "company_name"=>nil, "linkedin_url"=>nil, "avatar_url"=>"http://dge9rmgqjs8m1.cloudfront.net/highrise/missing/avatar.gif?r=3", "contact_data"=>#<Highrise::Person::ContactData:0x9db0a98 @attributes={"instant_messengers"=>[], "twitter_accounts"=>[], "email_addresses"=>[], "phone_numbers"=>[], "addresses"=>[], "web_addresses"=>[]}, @prefix_options={}, @persisted=true>, "subject_datas"=>[#<Highrise::Person::SubjectData:0x9dafc88 @attributes={"id"=>118062439, "subject_field_id"=>878834, "subject_field_label"=>"Customer ID", "value"=>"A"}, @prefix_options={}, @persisted=true>]}, @prefix_options={}, @persisted=true>]
|
11
18
|
|
12
19
|
|
20
|
+
########### conversion tests
|
21
|
+
###################### contact
|
13
22
|
class Contact
|
14
|
-
|
23
|
+
include HighriseWrapper::ActiveRecord
|
24
|
+
include Virtus.model
|
25
|
+
|
26
|
+
attribute :name, String
|
27
|
+
attribute :last_name, String
|
28
|
+
attribute :company_name, String
|
29
|
+
attribute :job_title, String
|
30
|
+
attribute :phone, String
|
31
|
+
attribute :website, String
|
32
|
+
attribute :email, String
|
33
|
+
|
34
|
+
def initialize attributes
|
35
|
+
attributes.each { |k, v| instance_variable_set("@#{k}", v) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
c = Contact.new({
|
40
|
+
:email => "ha@hihi.com",
|
41
|
+
:name => "Astolfo",
|
42
|
+
:last_name => "Aguiar",
|
43
|
+
:company_name => "AspasCorp",
|
44
|
+
:job_title => "Auxiliar",
|
45
|
+
:phone => "",
|
46
|
+
:website => ""})
|
47
|
+
|
48
|
+
puts 'the contact'
|
49
|
+
puts c.as_json
|
50
|
+
puts
|
51
|
+
|
52
|
+
###################### mapping v1
|
53
|
+
class Person
|
54
|
+
attr_accessor :test_name, :test_last_name
|
55
|
+
|
56
|
+
def initialize site, user, attributes
|
57
|
+
@site = site
|
58
|
+
@user = user
|
59
|
+
attributes.each { |k, v| instance_variable_set("@test_#{k}", v) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
p = Person.new "site", "user", c.as_json
|
64
|
+
puts 'the person'
|
65
|
+
puts p.as_json
|
66
|
+
puts
|
67
|
+
|
68
|
+
###################### mapping v2
|
69
|
+
class PersonMapper
|
70
|
+
include Virtus.model
|
71
|
+
|
72
|
+
attribute :first_name, String
|
73
|
+
attribute :last_name, String
|
74
|
+
attribute :title, String
|
75
|
+
attribute :company_name, String
|
76
|
+
attribute :avatar_url, String
|
77
|
+
attribute :email, String
|
78
|
+
attribute :home_phone, String
|
79
|
+
end
|
80
|
+
|
81
|
+
mapper = SimpleAttributeMapper::Mapper.new({
|
82
|
+
:name => :first_name,
|
83
|
+
:job_title => :title,
|
84
|
+
:phone => :home_phone
|
85
|
+
})
|
15
86
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
87
|
+
p2 = mapper.map(c, PersonMapper)
|
88
|
+
puts 'the person (mapped)'
|
89
|
+
puts p2.as_json
|
90
|
+
puts
|
21
91
|
|
22
|
-
|
23
|
-
|
92
|
+
###################### mapping v3
|
93
|
+
|
94
|
+
hmapper = SimpleAttributeMapper::Mapper.new({
|
95
|
+
:name => :first_name,
|
96
|
+
})
|
97
|
+
|
98
|
+
hp = hmapper.map(c, Highrise::Person)
|
99
|
+
puts 'the highrise person (mapped directly)'
|
100
|
+
puts hp.as_json
|
101
|
+
puts
|
102
|
+
|
103
|
+
###################### mapping v4
|
104
|
+
|
105
|
+
hp2 = Highrise::Person.new(p2.attributes)
|
106
|
+
puts 'the highrise person (mapped with person mapper)'
|
107
|
+
puts hp2.as_json
|
108
|
+
puts
|
109
|
+
|
110
|
+
###################### mapping v5
|
111
|
+
|
112
|
+
class ContactDataMapper
|
113
|
+
include Virtus.model
|
114
|
+
|
115
|
+
attribute :email_addresses, Array
|
116
|
+
attribute :phone_numbers, Array
|
117
|
+
attribute :web_addresses, Array
|
118
|
+
end
|
119
|
+
|
120
|
+
class PersonMapper2
|
121
|
+
include Virtus.model
|
122
|
+
|
123
|
+
attribute :first_name, String
|
124
|
+
attribute :last_name, String
|
125
|
+
attribute :title, String
|
126
|
+
attribute :company_name, String
|
127
|
+
attribute :avatar_url, String
|
128
|
+
attribute :email, String
|
129
|
+
attribute :contact_data, ContactDataMapper
|
130
|
+
end
|
131
|
+
|
132
|
+
SimpleAttributeMapper.from(c).to(PersonMapper2).with({
|
133
|
+
:name => :first_name,
|
134
|
+
:job_title => :title,
|
135
|
+
})
|
136
|
+
|
137
|
+
|
138
|
+
###################### mapping v6
|
139
|
+
|
140
|
+
def highrise_hash(contact)
|
141
|
+
{
|
142
|
+
'first_name' => contact.name,
|
143
|
+
'last_name' => contact.last_name,
|
144
|
+
'title' => contact.job_title,
|
145
|
+
'company_name' => contact.company_name,
|
146
|
+
'contact_data' => {
|
147
|
+
'email_addresses' => [{
|
148
|
+
'address' => contact.email,
|
149
|
+
'location' => 'Work'
|
150
|
+
}],
|
151
|
+
'phone_numbers' => [{
|
152
|
+
'number' => contact.phone,
|
153
|
+
'location' => 'Work'
|
154
|
+
}],
|
155
|
+
'web_addresses' => [{
|
156
|
+
'location' => 'Work',
|
157
|
+
'url' => contact.website
|
158
|
+
}]
|
159
|
+
}
|
160
|
+
}
|
24
161
|
end
|
25
162
|
|
26
|
-
|
27
|
-
|
28
|
-
puts
|
163
|
+
hp3 = Highrise::Person.new(highrise_hash(c))
|
164
|
+
puts 'the highrise person (mapped with hash)'
|
165
|
+
puts hp3.as_json
|
166
|
+
puts
|
167
|
+
|
29
168
|
|
169
|
+
#puts @people.to_json
|
30
170
|
=begin
|
31
171
|
{
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
172
|
+
"author_id":1018065,
|
173
|
+
"background":null,
|
174
|
+
"company_id":202863650,
|
175
|
+
"created_at":"2014-03-17T22:11:22Z",
|
176
|
+
"first_name":"Roberto",
|
177
|
+
"group_id":null,
|
178
|
+
"id":201374388,
|
179
|
+
"last_name":"Lobo",
|
180
|
+
"owner_id":null,
|
181
|
+
"title":"Project Manager",
|
182
|
+
"updated_at":"2014-03-29T20:40:56Z",
|
183
|
+
"visible_to":"Everyone",
|
184
|
+
"company_name":"Empresa",
|
185
|
+
"linkedin_url":null,
|
186
|
+
"avatar_url":"http://dge9rmgqjs8m1.cloudfront.net/highrise/missing/avatar.gif?r=3",
|
187
|
+
"contact_data": {
|
188
|
+
"instant_messengers":[],
|
189
|
+
"twitter_accounts":[],
|
190
|
+
"email_addresses":[{
|
191
|
+
"address":"rhlobo+highrise@gmail.com",
|
192
|
+
"id":103683105,
|
193
|
+
"location":"Home"
|
194
|
+
}],
|
195
|
+
"phone_numbers":[{
|
196
|
+
"id":164635766,
|
197
|
+
"location":"Work",
|
198
|
+
"number":"84442234"
|
199
|
+
}],
|
200
|
+
"addresses":[],
|
201
|
+
"web_addresses":[{
|
202
|
+
"id":164635767,
|
203
|
+
"location":"Work",
|
204
|
+
"url":"http://how.i.drycode.it"
|
205
|
+
}]
|
206
|
+
},
|
207
|
+
"subject_datas":[{
|
208
|
+
"id":118062439,
|
209
|
+
"subject_field_id":878834,
|
210
|
+
"subject_field_label":"Customer ID",
|
211
|
+
"value":"ID"
|
212
|
+
}]
|
73
213
|
}
|
74
214
|
=end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: highrise_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rhlobo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,28 +28,28 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.1.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 3.1.0
|
69
69
|
description: ! "Gem to provide easy usage of Highrise API.\n Built
|
70
70
|
wrapping the highrise gem, it is a POC\n created by me in
|
71
71
|
order to study rubys platform"
|