infopark_webcrm_sdk 1.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ module Crm
2
+ # +TemplateSet+ represents the Infopark WebCRM template set singleton.
3
+ # The templates of the {.singleton template set singleton} can be used to render customized text,
4
+ # e.g. a mailing greeting or a password request e-mail body (+password_request_email_body+).
5
+ #
6
+ # Infopark WebCRM uses the {http://liquidmarkup.org/ Liquid template engine} for evaluating
7
+ # the templates.
8
+ # @api public
9
+ class TemplateSet < Core::BasicResource
10
+ include Core::Mixins::ChangeLoggable
11
+ include Core::Mixins::Inspectable
12
+
13
+ def self.path
14
+ resource_name
15
+ end
16
+
17
+ # Returns the template set singleton.
18
+ # @return [TemplateSet]
19
+ # @api public
20
+ def self.singleton
21
+ new({}).reload
22
+ end
23
+
24
+ # Updates the attributes of this template set.
25
+ # See {Core::Mixins::Modifiable#update Modifiable#update} for details.
26
+ # @return [self] the updated template set singleton.
27
+ # @api public
28
+ def update(attributes)
29
+ load_attributes(
30
+ Core::RestApi.instance.put(path, attributes, if_match_header))
31
+ end
32
+
33
+ # Renders a preview of the template set using the specified context items.
34
+ # This is for testing your (future) templates.
35
+ #
36
+ # * All templates contained in the set are rendered.
37
+ # * You may temporally add any number of +templates+ to the set
38
+ # (just for the purpose of rendering).
39
+ # * Pass as +context+ items all the instances (e.g. contact, acticity)
40
+ # for which the templates should be rendered.
41
+ #
42
+ # Templates have access to the context items.
43
+ # You can use the following keys to represent context items:
44
+ # * +account+
45
+ # * +contact+
46
+ # * +activity+
47
+ # * +mailing+
48
+ # * +event+
49
+ # The keys expect an ID as input. For example, <tt>{"account" => "23"}</tt> allows
50
+ # the template to access +account.name+ of the account with the ID +23+.
51
+ #
52
+ # @example
53
+ # contact.first_name
54
+ # # => 'Michael'
55
+ #
56
+ # template_set.templates['digest_email_subject']
57
+ # # => 'Summary for {{contact.first_name}}'
58
+ #
59
+ # template_set.render_preview(
60
+ # templates: { greeting: 'Dear {{contact.first_name}}, {{foo}}' },
61
+ # context: {contact: contact.id, foo: 'welcome!'}
62
+ # )
63
+ # # => {
64
+ # # ...
65
+ # # 'digest_email_subject' => 'Summary for Michael',
66
+ # # 'greeting' => 'Dear Michael, welcome!',
67
+ # # ...
68
+ # # }
69
+ # @param templates [Hash{String => String}]
70
+ # the set of additional or temporary replacement templates to render.
71
+ # @param context [Hash{String => String}] the context items of the preview.
72
+ # @return [Hash{String => String}] the processed templates.
73
+ # @api public
74
+ def render_preview(templates: {}, context: {})
75
+ Core::RestApi.instance.post("#{path}/render_preview", {
76
+ 'templates' => templates,
77
+ 'context' => context,
78
+ })
79
+ end
80
+ end
81
+ end
data/lib/crm/type.rb ADDED
@@ -0,0 +1,78 @@
1
+ module Crm
2
+ # An Infopark WebCRM type defines a set of attributes associated with every instance of the type.
3
+ # @example Listing all attributes of a type
4
+ # account_type = Crm::Type.find('account')
5
+ # # => Crm::Type
6
+ #
7
+ # # Listing all standard attributes
8
+ # account_type.standard_attribute_definitions.keys
9
+ # # => ['name', 'created_at', 'updated_at', ...]
10
+ #
11
+ # # Listing all custom attributes
12
+ # account_type.attribute_definitions.keys
13
+ # # => ['custom_plan', ...]
14
+ #
15
+ # @example Inspecting an attribute definition of a type
16
+ # account_type.standard_attribute_definitions["name"]
17
+ # # => {
18
+ # # 'attribute_type' => 'string',
19
+ # # 'create' => true,
20
+ # # 'mandatory' => true,
21
+ # # 'read' => true,
22
+ # # 'title' => 'Name',
23
+ # # 'update' => true,
24
+ # # }
25
+ #
26
+ # @example Adding a new custom attribute to a type
27
+ # account_type.attribute_definitions.keys
28
+ # # => ['custom_plan']
29
+ #
30
+ # # Add a new custom attribute named "custom_shipping_details"
31
+ # attr_defs = account_type.attribute_definitions.merge({
32
+ # custom_shipping_details: {
33
+ # attribute_type: 'text',
34
+ # title: 'Shipping Details',
35
+ # }
36
+ # })
37
+ # account_type.update({
38
+ # attribute_definitions: attr_defs,
39
+ # })
40
+ # # => Crm::Type
41
+ #
42
+ # account_type.attribute_definitions.keys
43
+ # # => ['custom_plan', 'custom_shipping_details']
44
+ #
45
+ # @example Removing a custom attribute from a type
46
+ # account_type.attribute_definitions.keys
47
+ # # => ['custom_plan', 'custom_shipping_details']
48
+ #
49
+ # attr_defs = account_type.attribute_definitions.except('custom_shipping_details')
50
+ # account_type.update({
51
+ # attribute_definitions: attr_defs,
52
+ # })
53
+ # # => Crm::Type
54
+ #
55
+ # account_type.attribute_definitions.keys
56
+ # # => ['custom_plan']
57
+ # @api public
58
+ class Type < Core::BasicResource
59
+ include Core::Mixins::Findable
60
+ include Core::Mixins::Modifiable
61
+ include Core::Mixins::ChangeLoggable
62
+ include Core::Mixins::Inspectable
63
+ inspectable :id, :item_base_type
64
+
65
+ # @!parse extend Core::Mixins::Findable::ClassMethods
66
+ # @!parse extend Core::Mixins::Modifiable::ClassMethods
67
+
68
+ # Returns all types.
69
+ # @param include_deleted [Boolean] whether to include deleted types. Default: +false+.
70
+ # @return [Array<Type>]
71
+ # @api public
72
+ def self.all(include_deleted: false)
73
+ Core::RestApi.instance.get('types', { include_deleted: include_deleted }).map do |item|
74
+ new(item)
75
+ end
76
+ end
77
+ end
78
+ end
data/lib/crm.rb ADDED
@@ -0,0 +1,154 @@
1
+ require 'active_support/all'
2
+ require 'net/http/post/multipart'
3
+ require 'crm/errors'
4
+
5
+ # @api public
6
+ module Crm
7
+ # Configures the Infopark WebCRM SDK.
8
+ # The config keys +tenant+, +login+ and +api_key+ must be provided.
9
+ # @example
10
+ # Crm.configure do |config|
11
+ # config.tenant = 'my_tenant'
12
+ # config.login = 'my_login'
13
+ # config.api_key = 'my_api_key'
14
+ # end
15
+ # @yieldparam config [Crm::Core::Configuration]
16
+ # @return [void]
17
+ # @api public
18
+ def self.configure
19
+ config = ::Crm::Core::Configuration.new
20
+ yield config
21
+ config.validate!
22
+ Core::RestApi.instance = Core::RestApi.new(config.endpoint_uri, config.login, config.api_key)
23
+ end
24
+
25
+ def self.autoload_module(mod, mod_source)
26
+ mod_dir = mod_source.gsub(/\.rb$/, '')
27
+ Dir.glob("#{mod_dir}/*.rb").each do |file|
28
+ name = File.basename(file, ".rb")
29
+ mod.autoload name.camelcase, file
30
+ end
31
+ end
32
+
33
+ # Fetches multiple items by +ids+.
34
+ # The base type of the items can be mixed (e.g. a {Crm::Contact} or {Crm::Account}).
35
+ # @example
36
+ # Crm.find('e70a7123f499c5e0e9972ab4dbfb8fe3')
37
+ # # => Crm::Contact
38
+ #
39
+ # Crm.find('e70a7123f499c5e0e9972ab4dbfb8fe3', '2185dd25c2f4fa41fbef422c1b9cfc38')
40
+ # # => Crm::Core::ItemEnumerator
41
+ #
42
+ # Crm.find(['e70a7123f499c5e0e9972ab4dbfb8fe3', '2185dd25c2f4fa41fbef422c1b9cfc38'])
43
+ # # => Crm::Core::ItemEnumerator
44
+ # @param ids [String, Array<String>] A single ID or a list of IDs.
45
+ # @return [Crm::Core::BasicResource]
46
+ # A {Crm::Core::BasicResource single item} if the method was called with a single ID.
47
+ # @return [Crm::Core::ItemEnumerator]
48
+ # An {Crm::Core::ItemEnumerator enumerator} if the method was called with multiple IDs.
49
+ # @raise [Errors::ResourceNotFound] if at least one of the IDs could not be found.
50
+ # @api public
51
+ def self.find(*ids)
52
+ flattened_ids = ids.flatten
53
+ if flattened_ids.compact.blank?
54
+ raise Crm::Errors::ResourceNotFound.new(
55
+ "Items could not be found.", flattened_ids)
56
+ end
57
+ enumerator = Core::ItemEnumerator.new(flattened_ids)
58
+
59
+ if ids.size == 1 && !ids.first.kind_of?(Array)
60
+ enumerator.first
61
+ else
62
+ enumerator
63
+ end
64
+ end
65
+
66
+ # Performs a search.
67
+ # Retrieves only IDs and passes them to an {Core::ItemEnumerator ItemEnumerator}.
68
+ # The {Core::ItemEnumerator ItemEnumerator} then fetches the items on demand.
69
+ #
70
+ # The search considers the following base types:
71
+ # * {Crm::Account Account}
72
+ # * {Crm::Activity Activity}
73
+ # * {Crm::Collection Collection}
74
+ # * {Crm::Contact Contact}
75
+ # * {Crm::Event Event}
76
+ # * {Crm::EventContact EventContact}
77
+ # * {Crm::Mailing Mailing}
78
+ # @example
79
+ # Crm.search([{field: 'last_name', condition: 'equals', value: 'Johnson'}])
80
+ # # => Crm::Core::ItemEnumerator with max 10 contacts with last name Johnson.
81
+ #
82
+ # Crm.search(
83
+ # [
84
+ # {field: 'last_name', condition: 'equals', value: 'Johnson'},
85
+ # {field: 'locality', condition: 'equals', value: 'Boston'}
86
+ # ],
87
+ # limit: 20,
88
+ # offset: 10,
89
+ # sort_by: 'created_at',
90
+ # sort_order: 'desc',
91
+ # include_deleted: true
92
+ # )
93
+ # # => Crm::Core::ItemEnumerator with max 20 contacts with last name Johnson from Boston.
94
+ # @param filters [Array<Hash{String => String}>]
95
+ # Array of filters, each filter is a hash with three properties:
96
+ # +field+, +condition+, +value+. Filters are AND expressions.
97
+ # @param query [String]
98
+ # The search term of a full-text search for words starting with the term
99
+ # (case-insensitive prefix search). Affects score.
100
+ # @param limit [Fixnum] The number of results to return at most. Minimum: +0+.
101
+ # Use +:none+ to specify no limit. Default: +10+.
102
+ # @param offset [Fixnum] The number of results to skip. Minimum: +0+. Default: +0+.
103
+ # @param sort_by [String] The name of the attribute by which the result is to be sorted:
104
+ # * +base_type+
105
+ # * +created_at+ (server default)
106
+ # * +dtstart_at+
107
+ # * +first_name+
108
+ # * +last_name+
109
+ # * +score+
110
+ # * +title+
111
+ # * +updated_at+
112
+ # @param sort_order [String] One of +asc+ (ascending) or +desc+ (descending).
113
+ # For +sort_by+ +score+, the only valid sort order is +desc+ (can be omitted).
114
+ # @param include_deleted [Boolean]
115
+ # whether to include deleted items in the results. Server default: +false+.
116
+ # @return [Crm::Core::ItemEnumerator]
117
+ # An {Crm::Core::ItemEnumerator enumerator} to iterate over the found items.
118
+ # @api public
119
+ def self.search(filters: nil, query: nil, limit: nil, offset: nil, sort_by: nil,
120
+ sort_order: nil, include_deleted: nil)
121
+ server_limit = 100
122
+ limit ||= 10
123
+ limit = Float::INFINITY if limit == :none
124
+ offset ||= 0
125
+
126
+ ids = []
127
+ total = nil
128
+ initial_offset = offset
129
+
130
+ loop do
131
+ params = {
132
+ 'filters' => filters,
133
+ 'query' => query,
134
+ 'limit' => [limit, server_limit].min,
135
+ 'offset' => offset,
136
+ 'sort_by' => sort_by,
137
+ 'sort_order' => sort_order,
138
+ 'include_deleted' => include_deleted,
139
+ }.reject { |k, v| v.nil? }
140
+ search_results = Core::RestApi.instance.post('search', params)
141
+ ids.concat(search_results['results'].map { |r| r['id'] })
142
+ total = search_results['total']
143
+ break if ids.size >= [limit, (total - initial_offset)].min
144
+ limit -= server_limit
145
+ offset += server_limit
146
+ end
147
+
148
+ Core::ItemEnumerator.new(ids, total: total)
149
+ end
150
+
151
+ autoload_module(self, File.expand_path(__FILE__))
152
+ end
153
+
154
+ Crm::Core::LogSubscriber.attach_to :crm
@@ -0,0 +1 @@
1
+ require 'crm'
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infopark_webcrm_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc3
5
+ platform: ruby
6
+ authors:
7
+ - Infopark AG
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: multipart-post
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ description: "\n Infopark WebCRM is a professional cloud CRM built for Ruby.\n
84
+ \ For more information about Infopark WebCRM, please visit https://infopark.com/.\n
85
+ \ "
86
+ email: info@infopark.de
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - LICENSE
92
+ - README.md
93
+ - UPGRADE.md
94
+ - config/ca-bundle.crt
95
+ - lib/crm.rb
96
+ - lib/crm/account.rb
97
+ - lib/crm/activity.rb
98
+ - lib/crm/collection.rb
99
+ - lib/crm/contact.rb
100
+ - lib/crm/core.rb
101
+ - lib/crm/core/attachment_store.rb
102
+ - lib/crm/core/basic_resource.rb
103
+ - lib/crm/core/configuration.rb
104
+ - lib/crm/core/connection_manager.rb
105
+ - lib/crm/core/item_enumerator.rb
106
+ - lib/crm/core/log_subscriber.rb
107
+ - lib/crm/core/mixins.rb
108
+ - lib/crm/core/mixins/attribute_provider.rb
109
+ - lib/crm/core/mixins/change_loggable.rb
110
+ - lib/crm/core/mixins/findable.rb
111
+ - lib/crm/core/mixins/inspectable.rb
112
+ - lib/crm/core/mixins/merge_and_deletable.rb
113
+ - lib/crm/core/mixins/modifiable.rb
114
+ - lib/crm/core/mixins/searchable.rb
115
+ - lib/crm/core/rest_api.rb
116
+ - lib/crm/core/search_configurator.rb
117
+ - lib/crm/errors.rb
118
+ - lib/crm/event.rb
119
+ - lib/crm/event_contact.rb
120
+ - lib/crm/mailing.rb
121
+ - lib/crm/template_set.rb
122
+ - lib/crm/type.rb
123
+ - lib/infopark_webcrm_sdk.rb
124
+ homepage: https://infopark.com
125
+ licenses:
126
+ - LGPL-3.0
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">"
140
+ - !ruby/object:Gem::Version
141
+ version: 1.3.1
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Infopark WebCRM SDK
148
+ test_files: []
149
+ has_rdoc: