infopark_crm_connector 0.9.2 → 1.0.0
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.
- data/.yardopts +8 -0
- data/CHANGELOG.markdown +94 -0
- data/LICENSE +2 -0
- data/README.markdown +110 -0
- data/lib/crm_connector.rb +11 -15
- data/lib/crm_connector/account.rb +31 -2
- data/lib/crm_connector/activity.rb +61 -3
- data/lib/crm_connector/configuration.rb +2 -4
- data/lib/crm_connector/contact.rb +123 -3
- data/lib/crm_connector/core/continuation_support.rb +2 -1
- data/lib/crm_connector/core/enumerator.rb +20 -11
- data/lib/crm_connector/core/known_attributes.rb +3 -1
- data/lib/crm_connector/core/resource.rb +108 -16
- data/lib/crm_connector/core/search_support.rb +3 -1
- data/lib/crm_connector/custom_type.rb +20 -3
- data/lib/crm_connector/{default.rb → errors.rb} +1 -1
- data/lib/crm_connector/errors/authentication_failed.rb +10 -0
- data/lib/crm_connector/errors/base.rb +8 -0
- data/lib/crm_connector/event.rb +37 -2
- data/lib/crm_connector/event_contact.rb +38 -2
- data/lib/crm_connector/mailing.rb +35 -2
- data/lib/crm_connector/role.rb +7 -2
- data/lib/crm_connector/system.rb +14 -8
- metadata +22 -53
- data/CHANGELOG.rdoc +0 -87
- data/README.rdoc +0 -59
- data/lib/crm_connector/base.rb +0 -4
- data/lib/crm_connector/core/base.rb +0 -111
- data/lib/crm_connector/debugging.rb +0 -21
- data/lib/crm_connector/default/account.rb +0 -30
- data/lib/crm_connector/default/activity.rb +0 -54
- data/lib/crm_connector/default/contact.rb +0 -112
- data/lib/crm_connector/default/custom_type.rb +0 -24
- data/lib/crm_connector/default/event.rb +0 -23
- data/lib/crm_connector/default/event_contact.rb +0 -57
- data/lib/crm_connector/default/mailing.rb +0 -33
- data/lib/crm_connector/default/resource.rb +0 -10
- data/lib/crm_connector/default/role.rb +0 -9
- data/lib/crm_connector/inheriting_resource.rb +0 -30
- data/lib/crm_connector/resource.rb +0 -15
@@ -1,42 +1,51 @@
|
|
1
1
|
require 'backports'
|
2
2
|
|
3
3
|
module Infopark; module Crm; module Core
|
4
|
-
# Transparent wrapper for the web
|
4
|
+
# Transparent wrapper for the web services continuation ability
|
5
5
|
class Enumerator < Enumerator
|
6
|
-
|
6
|
+
|
7
|
+
# @private
|
8
|
+
def initialize(collection, continuation_handle, size, &block)
|
7
9
|
update(collection, continuation_handle, size)
|
8
10
|
super &block
|
9
11
|
end
|
10
12
|
|
13
|
+
##
|
11
14
|
# The +continuation_handle+ parameter to be passed to the next find or search request for
|
12
|
-
# programmatic paging
|
15
|
+
# programmatic paging.
|
16
|
+
# @return [String]
|
17
|
+
# @private
|
13
18
|
def continuation_handle
|
14
19
|
@continuation_handle
|
15
20
|
end
|
16
21
|
|
17
|
-
|
18
|
-
#
|
22
|
+
##
|
23
|
+
# The results of the last response as an array.
|
24
|
+
# The size of the array is less than or equal to the +limit+ parameter value.
|
25
|
+
# @return [Array]
|
19
26
|
def within_limit
|
20
27
|
@collection
|
21
28
|
end
|
22
29
|
|
23
30
|
##
|
24
|
-
#
|
31
|
+
# @!method size
|
25
32
|
# The total count given by the last search response, if available.
|
26
|
-
#
|
33
|
+
# If not available this method is undefiend.
|
34
|
+
# @return [Integer] The total count given by the last search response, if available.
|
27
35
|
##
|
28
36
|
|
29
|
-
|
37
|
+
##
|
30
38
|
# Note: We don't want size to return nil for compatibility for count's behavior
|
31
|
-
|
32
|
-
def update(collection, continuation_handle, size)
|
39
|
+
# @private
|
40
|
+
def update(collection, continuation_handle, size)
|
33
41
|
@collection = collection
|
34
42
|
@continuation_handle = continuation_handle
|
35
43
|
@size = size
|
36
44
|
define_singleton_method(:size) {@size} if @size
|
37
45
|
end
|
38
46
|
|
39
|
-
|
47
|
+
# @private
|
48
|
+
def inspect
|
40
49
|
"#{super.chop}, @within_limit=#{within_limit.inspect}" +
|
41
50
|
", @continuation_handle=#{continuation_handle.inspect}>"
|
42
51
|
end
|
@@ -1,18 +1,37 @@
|
|
1
|
-
|
2
|
-
require 'ostruct'
|
1
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
3
2
|
|
4
3
|
module Infopark; module Crm; module Core
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
##
|
5
|
+
# Base class for every resource model
|
6
|
+
#
|
7
|
+
# Supports the ActiveResource::Base lifecycle methods, such as
|
8
|
+
# * Resource.create(attributes)
|
9
|
+
# * Resource.new(attributes)
|
10
|
+
# * Resource.find(id)
|
11
|
+
# * resource.update_attributes(attributes)
|
12
|
+
# * resource.save
|
13
|
+
#
|
14
|
+
# See the {http://rubydoc.info/gems/activeresource/3.2.8/frames ActiveResource documentation} for a detailed description.
|
15
|
+
class Resource < ActiveResource::Base
|
16
|
+
include ContinuationSupport
|
17
|
+
include SearchSupport
|
8
18
|
|
9
|
-
|
10
|
-
|
19
|
+
self.format = :json
|
20
|
+
self.include_root_in_json = true
|
21
|
+
|
22
|
+
cattr_accessor :locale
|
23
|
+
cattr_accessor :http_host
|
24
|
+
|
25
|
+
# @private
|
26
|
+
def self.element_name
|
27
|
+
@element_name ||= first_resource_child.model_name.element
|
11
28
|
end
|
12
29
|
|
30
|
+
# @private
|
13
31
|
@@deprecation_warnings = true
|
14
32
|
cattr_writer :deprecation_warnings
|
15
33
|
|
34
|
+
# @private
|
16
35
|
def self.deprecated(deprecated, hint = nil)
|
17
36
|
return unless @@deprecation_warnings
|
18
37
|
text = "[WebCrmConnector] #{deprecated} is deprecated."
|
@@ -24,21 +43,94 @@ module Infopark; module Crm; module Core
|
|
24
43
|
end
|
25
44
|
end
|
26
45
|
|
46
|
+
# @private
|
27
47
|
def known_attributes
|
28
|
-
KnownAttributes.new(super)
|
48
|
+
Core::KnownAttributes.new(super)
|
29
49
|
end
|
30
50
|
|
31
|
-
|
32
|
-
|
33
|
-
|
51
|
+
##
|
52
|
+
# @webcrm_todo remove when https://github.com/rails/rails/issues/2479 is done
|
53
|
+
# @private
|
54
|
+
def self.delete(id, options = {})
|
55
|
+
connection.delete(element_path(id, options), headers)
|
34
56
|
end
|
35
57
|
|
36
|
-
|
37
|
-
|
38
|
-
|
58
|
+
# @private
|
59
|
+
def self.headers
|
60
|
+
headers = super
|
61
|
+
headers.merge!({"Accept-Language" => self.locale}) if self.locale
|
62
|
+
headers.merge!({"Host" => self.http_host}) if self.http_host
|
63
|
+
headers
|
39
64
|
end
|
40
65
|
|
41
|
-
#
|
42
|
-
|
66
|
+
# @private
|
67
|
+
def self.configure(configuration)
|
68
|
+
self.site = configuration.url + '/api/' if configuration.url
|
69
|
+
self.user = configuration.login
|
70
|
+
self.password = configuration.api_key
|
71
|
+
self.locale = configuration.locale
|
72
|
+
self.http_host = configuration.http_host
|
73
|
+
end
|
74
|
+
|
75
|
+
# @private
|
76
|
+
def self.schema=(definition)
|
77
|
+
ares_compatible_definition = {}
|
78
|
+
definition.each do |k, v|
|
79
|
+
ares_compatible_definition[k] = SchemaSupport.schema_type(v)
|
80
|
+
end
|
81
|
+
super(ares_compatible_definition)
|
82
|
+
end
|
83
|
+
|
84
|
+
###
|
85
|
+
# @webcrm_todo drop when ActiveResource 3.0 support is dropped
|
86
|
+
# @private
|
87
|
+
class SchemaSupport
|
88
|
+
def self.schema_mapping
|
89
|
+
@schema_mapping ||= {}
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.add(mapping)
|
93
|
+
schema_mapping.merge!(mapping)
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.schema_type(type)
|
97
|
+
default_mapping = ::ActiveResource::Schema::KNOWN_ATTRIBUTE_TYPES
|
98
|
+
return type if default_mapping.include?(type.to_s)
|
99
|
+
return schema_mapping[type.to_sym]
|
100
|
+
end
|
43
101
|
|
102
|
+
add :text => :string
|
103
|
+
add :date => :string
|
104
|
+
add :boolean => nil
|
105
|
+
end
|
106
|
+
|
107
|
+
# Support for field associatable errors (without humanized name guessing)
|
108
|
+
# @private
|
109
|
+
def errors
|
110
|
+
@errors ||= Errors.new(self)
|
111
|
+
end
|
112
|
+
|
113
|
+
# @private
|
114
|
+
class Errors < ActiveResource::Errors
|
115
|
+
|
116
|
+
##
|
117
|
+
# @webcrm_todo temporary patch from https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5616
|
118
|
+
def from_json(json, save_cache = false)
|
119
|
+
errors = ActiveSupport::JSON.decode(json)
|
120
|
+
clear unless save_cache
|
121
|
+
errors.each do |attr_name, messages|
|
122
|
+
Array.wrap(messages).each { |message| add(attr_name.to_sym, message) }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def self.first_resource_child
|
131
|
+
ancestors.each_cons(2) do |child, parent|
|
132
|
+
return child if (parent == Infopark::Crm::Core::Resource)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
44
136
|
end; end; end
|
@@ -1,7 +1,24 @@
|
|
1
1
|
module Infopark; module Crm
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class CustomType < Core::Resource
|
3
|
+
self.schema = {
|
4
|
+
:custom_attributes => :hash,
|
5
|
+
:icon_css_class => :string,
|
6
|
+
:kind => :string,
|
7
|
+
:name => :string,
|
8
|
+
:states => :array,
|
9
|
+
}
|
10
|
+
|
11
|
+
# @private
|
12
|
+
class CustomAttribute < Core::Resource
|
13
|
+
|
14
|
+
self.include_root_in_json = false
|
15
|
+
|
16
|
+
###
|
17
|
+
# @webcrm_todo this method is only needed until the deprecated Object#type is removed
|
18
|
+
# Better: define self.schema
|
19
|
+
def type
|
20
|
+
attributes['type']
|
21
|
+
end
|
5
22
|
end
|
6
23
|
end
|
7
24
|
end; end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Infopark; module Crm; module Errors
|
2
|
+
|
3
|
+
##
|
4
|
+
# Raised when a contact provides wrong credentials (token/password)
|
5
|
+
#
|
6
|
+
# This differs from the case when the web services API credentials are not accepted
|
7
|
+
# (an ActiveResource error is raised then)
|
8
|
+
class AuthenticationFailed < Base; end
|
9
|
+
|
10
|
+
end; end; end
|
data/lib/crm_connector/event.rb
CHANGED
@@ -1,4 +1,39 @@
|
|
1
1
|
module Infopark; module Crm
|
2
|
-
|
3
|
-
|
2
|
+
class Event < Core::Resource
|
3
|
+
|
4
|
+
##
|
5
|
+
# @!method self.search(input)
|
6
|
+
# Searches for events
|
7
|
+
# @param input [Hash] A hash containing a +params+ key. The value of this key is a hash containing the actual search query.
|
8
|
+
# @return [Array<Infopark::Crm::Event>]
|
9
|
+
# @webcrm_rest_url <code>GET /api/events/search</code>
|
10
|
+
# @example
|
11
|
+
# results = Infopark::Crm::Event.search(:params => {:kind => kind})
|
12
|
+
# results = Infopark::Crm::Event.search(:params => {:event_set => event_set})
|
13
|
+
# results = Infopark::Crm::Event.search(:params => {:q => 'full-text search'})
|
14
|
+
has_search
|
15
|
+
|
16
|
+
self.schema = {
|
17
|
+
:custom_attributes => :hash,
|
18
|
+
:dtend_at => :time,
|
19
|
+
:dtstart_at => :time,
|
20
|
+
:event_set => :string,
|
21
|
+
:kind => :string,
|
22
|
+
:location => :string,
|
23
|
+
:title => :string,
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# @private
|
28
|
+
class Event::CustomAttribute < Core::Resource
|
29
|
+
|
30
|
+
self.include_root_in_json = false
|
31
|
+
|
32
|
+
##
|
33
|
+
# @webcrm_todo this method is only needed until the deprecated Object#type is removed
|
34
|
+
# Better: define self.schema
|
35
|
+
def type
|
36
|
+
attributes['type']
|
37
|
+
end
|
38
|
+
end
|
4
39
|
end; end
|
@@ -1,4 +1,40 @@
|
|
1
1
|
module Infopark; module Crm
|
2
|
-
|
3
|
-
|
2
|
+
class EventContact < Core::Resource
|
3
|
+
|
4
|
+
##
|
5
|
+
# @!method self.search(input)
|
6
|
+
# Searches for event contacts
|
7
|
+
# @param input [Hash] A hash containing a +params+ key. The value of this key is a hash containing the actual search query.
|
8
|
+
# @return [Array<Infopark::Crm::EventContact>]
|
9
|
+
# @webcrm_rest_url <code>GET /api/event_contacts/search</code>
|
10
|
+
# @example
|
11
|
+
# results = Infopark::Crm::EventContacts.search(:params => {:event_id => eid})
|
12
|
+
# results = Infopark::Crm::EventContacts.search(:params => {:contact_id => cid})
|
13
|
+
# results = Infopark::Crm::EventContacts.search(:params => {:state => state})
|
14
|
+
# results = Infopark::Crm::EventContacts.search(:params => {:q => 'full-text search'})
|
15
|
+
has_search
|
16
|
+
|
17
|
+
self.schema = {
|
18
|
+
:state => :string,
|
19
|
+
:contact_id => :string,
|
20
|
+
:event_id => :string,
|
21
|
+
}
|
22
|
+
|
23
|
+
##
|
24
|
+
# Queries the WebCRM for the Contact with the id +contact_id+.
|
25
|
+
# @return [Infopark::Crm::Contact] The contact associated with this event contact, if +contact_id+ is present.
|
26
|
+
# @webcrm_rest_url <code>GET /api/contacts/_contact_id_</code>
|
27
|
+
def contact
|
28
|
+
Infopark::Crm::Contact.find(contact_id) if contact_id
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Queries the WebCRM for the Event with the id +event_id+.
|
33
|
+
# @return [Infopark::Crm::Event] The event associated with this event contact, if +event_id+ is present.
|
34
|
+
# @webcrm_rest_url <code>GET /api/events/_event_id_</code>
|
35
|
+
def event
|
36
|
+
Infopark::Crm::Event.find(event_id) if event_id
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
4
40
|
end; end
|
@@ -1,4 +1,37 @@
|
|
1
1
|
module Infopark; module Crm
|
2
|
-
|
3
|
-
|
2
|
+
class Mailing < Core::Resource
|
3
|
+
|
4
|
+
##
|
5
|
+
# @!method self.search(input)
|
6
|
+
# Searches for mailings
|
7
|
+
# @param input [Hash] A hash containing a +params+ key. The value of this key is a hash containing the actual search query.
|
8
|
+
# @return [Array<Infopark::Crm::Mailing>]
|
9
|
+
# @webcrm_rest_url <code>GET /api/mailings/search</code>
|
10
|
+
# @example
|
11
|
+
# results = Infopark::Crm::Mailing.search(:params => {:event_id => event_id})
|
12
|
+
# results = Infopark::Crm::Mailing.search(:params => {:only_unreleased => true})
|
13
|
+
# results = Infopark::Crm::Mailing.search(:params => {:q => 'full-text search'})
|
14
|
+
has_search
|
15
|
+
|
16
|
+
self.schema = {
|
17
|
+
:body => :string,
|
18
|
+
:dtstart_at => :time,
|
19
|
+
:email_from => :string,
|
20
|
+
:email_reply_to => :string,
|
21
|
+
:email_subject => :string,
|
22
|
+
:event_id => :string,
|
23
|
+
:html_body => :string,
|
24
|
+
:mailing_type => :string,
|
25
|
+
:title => :string,
|
26
|
+
}
|
27
|
+
|
28
|
+
##
|
29
|
+
# Queries the WebCRM for the Event with the id +event_id+.
|
30
|
+
# @return [Infopark::Crm::Event] The event associated with this event contact, if +event_id+ is present.
|
31
|
+
# @webcrm_rest_url <code>GET /api/events/_event_id_</code>
|
32
|
+
def event
|
33
|
+
Infopark::Crm::Event.find(event_id) if event_id
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
4
37
|
end; end
|
data/lib/crm_connector/role.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
module Infopark; module Crm
|
2
|
-
|
3
|
-
|
2
|
+
class Role < Core::Resource
|
3
|
+
self.schema = {
|
4
|
+
:description => :string,
|
5
|
+
:name => :string,
|
6
|
+
:permissions => :array,
|
7
|
+
}
|
8
|
+
end
|
4
9
|
end; end
|