infopark_webcrm_sdk 1.0.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/crm.rb CHANGED
@@ -87,8 +87,7 @@ module Crm
87
87
  # limit: 20,
88
88
  # offset: 10,
89
89
  # sort_by: 'created_at',
90
- # sort_order: 'desc',
91
- # include_deleted: true
90
+ # sort_order: 'desc'
92
91
  # )
93
92
  # # => Crm::Core::ItemEnumerator with max 20 contacts with last name Johnson from Boston.
94
93
  # @param filters [Array<Hash{String => String}>]
@@ -111,13 +110,10 @@ module Crm
111
110
  # * +updated_at+
112
111
  # @param sort_order [String] One of +asc+ (ascending) or +desc+ (descending).
113
112
  # 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
113
  # @return [Crm::Core::ItemEnumerator]
117
114
  # An {Crm::Core::ItemEnumerator enumerator} to iterate over the found items.
118
115
  # @api public
119
- def self.search(filters: nil, query: nil, limit: :none, offset: 0, sort_by: nil,
120
- sort_order: nil, include_deleted: nil)
116
+ def self.search(filters: nil, query: nil, limit: :none, offset: 0, sort_by: nil, sort_order: nil)
121
117
  server_limit = 100
122
118
  limit = Float::INFINITY if limit.nil? || limit == :none
123
119
  offset ||= 0
@@ -134,7 +130,6 @@ module Crm
134
130
  'offset' => offset,
135
131
  'sort_by' => sort_by,
136
132
  'sort_order' => sort_order,
137
- 'include_deleted' => include_deleted,
138
133
  }.reject { |k, v| v.nil? }
139
134
  search_results = Core::RestApi.instance.post('search', params)
140
135
  ids.concat(search_results['results'].map { |r| r['id'] })
@@ -10,7 +10,7 @@ module Crm; module Core
10
10
  info { "#{event.payload[:method].to_s.upcase} #{event.payload[:resource_path]}" }
11
11
  request_payload = event.payload[:request_payload]
12
12
  if request_payload.present?
13
- debug { " request body: #{parameter_filter.filter(request_payload)}" }
13
+ debug { " request body: #{parameter_filter.filter({data: request_payload})[:data]}" }
14
14
  end
15
15
  end
16
16
 
@@ -21,7 +21,7 @@ module Crm; module Core
21
21
  }
22
22
  debug {
23
23
  response_payload = MultiJson.load(r.body)
24
- " response body: #{parameter_filter.filter(response_payload)}"
24
+ " response body: #{parameter_filter.filter({data: response_payload})[:data]}"
25
25
  }
26
26
  end
27
27
 
@@ -7,11 +7,10 @@ module Crm; module Core; module Mixins
7
7
  # whose ID is +merge_into_id+. Afterwards, the current item is deleted.
8
8
  # @param merge_into_id [String]
9
9
  # the ID of the account or contact to which the associated items are assigned.
10
- # @return [self] the deleted item.
11
10
  # @api public
12
11
  def merge_and_delete(merge_into_id)
13
- load_attributes(
14
- RestApi.instance.post("#{path}/merge_and_delete", {"merge_into_id" => merge_into_id}))
12
+ RestApi.instance.post("#{path}/merge_and_delete", {"merge_into_id" => merge_into_id})
13
+ nil
15
14
  end
16
15
  end
17
16
  end; end; end
@@ -2,7 +2,7 @@ require "active_support/concern"
2
2
 
3
3
  module Crm; module Core; module Mixins
4
4
  # +Modifiable+ is a collection of methods that are used to {ClassMethods#create .create},
5
- # {#update}, {#delete}, and {#undelete} an Infopark WebCRM item.
5
+ # {#update} and {#delete} an Infopark WebCRM item.
6
6
  # @api public
7
7
  module Modifiable
8
8
  extend ActiveSupport::Concern
@@ -54,47 +54,14 @@ module Crm; module Core; module Mixins
54
54
  load_attributes(RestApi.instance.put(path, attributes, if_match_header))
55
55
  end
56
56
 
57
- # Soft-deletes this item (i.e. marks it as deleted).
57
+ # Deletes this item.
58
58
  #
59
- # The deleted item can be {#undelete undeleted}.
60
- # @example
61
- # contact.deleted?
62
- # # => false
63
- #
64
- # contact.delete
65
- # # => Crm::Contact
66
- #
67
- # contact.deleted?
68
- # # => true
69
- # @return [self] the deleted item.
70
59
  # @raise [Errors::ResourceConflict] if the item has been changed concurrently.
71
60
  # {Core::BasicResource#reload Reload} it, review the changes and retry.
72
61
  # @api public
73
62
  def delete
74
- load_attributes(RestApi.instance.delete(path, nil, if_match_header))
75
- end
76
-
77
- # Undeletes this deleted item.
78
- # @example
79
- # contact.deleted?
80
- # # => true
81
- #
82
- # contact.undelete
83
- # # => Crm::Contact
84
- #
85
- # contact.deleted?
86
- # # => false
87
- # @return [self] the undeleted item.
88
- # @api public
89
- def undelete
90
- load_attributes(RestApi.instance.put("#{path}/undelete", {}))
91
- end
92
-
93
- # Returns +true+ if the item was deleted (i.e. +item.deleted_at+ is not empty).
94
- # @return [Boolean]
95
- # @api public
96
- def deleted?
97
- self['deleted_at'].present?
63
+ RestApi.instance.delete(path, nil, if_match_header)
64
+ nil
98
65
  end
99
66
 
100
67
  alias_method :destroy, :delete
@@ -19,14 +19,12 @@ module Crm; module Core; module Mixins
19
19
 
20
20
  # Returns an {Crm::Core::ItemEnumerator enumerator} for iterating over all items
21
21
  # of this base type. The items are sorted by +created_at+.
22
- # @param include_deleted [Boolean] whether to include deleted items. Default: +false+.
23
22
  # @return [ItemEnumerator]
24
23
  # @api public
25
- def all(include_deleted: false)
24
+ def all
26
25
  search_configurator.
27
26
  sort_by('created_at').
28
27
  unlimited.
29
- include_deleted(include_deleted).
30
28
  perform_search
31
29
  end
32
30
 
@@ -51,7 +51,6 @@ module Crm; module Core
51
51
  offset: @settings[:offset],
52
52
  sort_by: @settings[:sort_by],
53
53
  sort_order: @settings[:sort_order],
54
- include_deleted: @settings[:include_deleted]
55
54
  )
56
55
  end
57
56
 
@@ -165,23 +164,6 @@ module Crm; module Core
165
164
  sort_order('desc')
166
165
  end
167
166
 
168
- # Returns a new {SearchConfigurator} constructed by combining this configuration
169
- # with the given +include_deleted+ flag.
170
- # @param new_include_deleted [Boolean] whether to include deleted items in the results.
171
- # @return [SearchConfigurator]
172
- # @api public
173
- def include_deleted(new_include_deleted = true)
174
- SearchConfigurator.new(@settings.merge(include_deleted: new_include_deleted))
175
- end
176
-
177
- # Returns a new {SearchConfigurator} constructed by combining this configuration
178
- # and excluding deleted items.
179
- # @return [SearchConfigurator]
180
- # @api public
181
- def exclude_deleted
182
- include_deleted(false)
183
- end
184
-
185
167
  # @!endgroup
186
168
 
187
169
  # Iterates over the search results.
@@ -58,8 +58,7 @@ module Crm
58
58
  end
59
59
 
60
60
  # +ItemStatePreconditionFailed+ is raised if one or more preconditions
61
- # for the attempted action were not satisfied. For example, a deleted item cannot be updated.
62
- # It must be undeleted first.
61
+ # for the attempted action were not satisfied.
63
62
  # @api public
64
63
  class ItemStatePreconditionFailed < ClientError
65
64
  # Returns the unmet preconditions.
@@ -0,0 +1,95 @@
1
+ module Crm
2
+ # MailingDelivery represents a mailing delivery.
3
+ # @api public
4
+ class MailingDelivery
5
+ include Core::Mixins::Inspectable
6
+ include Core::Mixins::AttributeProvider
7
+
8
+ inspectable :mailing_id, :id
9
+
10
+ def self.all(mailing_id, since: nil)
11
+ path = ['mailings', mailing_id, 'mailing_deliveries'].compact.join('/')
12
+ params = {}
13
+ case since
14
+ when Time
15
+ params[:since] = since.utc.xmlschema
16
+ when String
17
+ params[:since] = since
18
+ when nil
19
+ # ignore
20
+ else
21
+ raise "unknown class of since param: #{since.class}"
22
+ end
23
+ Core::RestApi.instance.get(path, params).map {|attrs| new({'mailing_id' => mailing_id}.merge(attrs))}
24
+ end
25
+
26
+ # Creates or updates a mailing delivery.
27
+ # @example
28
+ # Crm::MailingDelivery.create(mailing.id, "abc@example.com", {
29
+ # custom_data: {
30
+ # salutation: 'Hello You',
31
+ # },
32
+ # })
33
+ # @param mailing_id [String] the mailing ID
34
+ # @param id [String] the email address
35
+ # @param attributes [Hash{String, Symbol => String}] the new attributes.
36
+ # @return [self] the created or updated mailing delivery.
37
+ # @api public
38
+ def self.create(mailing_id, id, attributes = {})
39
+ new({'mailing_id' => mailing_id, 'id' => id}).update(attributes)
40
+ end
41
+
42
+ # Returns the requested mailing delivery.
43
+ # @example
44
+ # d = Crm::MailingDelivery.find(mailing.id, "abc@example.com")
45
+ # # => #<Crm::MailingDelivery mailing_id="94933088cec0014575ff920ee9830cfb", id="abc@example.com">
46
+ # @param mailing_id [String] the mailing ID
47
+ # @param id [String] the email address
48
+ # @return [MailingDelivery]
49
+ # @api public
50
+ def self.find(mailing_id, id)
51
+ raise Crm::Errors::ResourceNotFound.new("Items could not be found.", [mailing_id]) if mailing_id.blank?
52
+ raise Crm::Errors::ResourceNotFound.new("Items could not be found.", [id]) if id.blank?
53
+
54
+ new({'mailing_id' => mailing_id, 'id' => id}).reload
55
+ end
56
+
57
+ # Deletes the mailing delivery.
58
+ #
59
+ # @raise [Errors::ResourceConflict] if the item has been changed concurrently.
60
+ # {Core::BasicResource#reload Reload} it, review the changes and retry.
61
+ # @api public
62
+ def delete
63
+ Core::RestApi.instance.delete(path, nil, if_match_header)
64
+ nil
65
+ end
66
+
67
+ # Updates the attributes of this mailing delivery.
68
+ # @example
69
+ # mailing_delivery.update({
70
+ # custom_data: {
71
+ # salutation: 'Hello You',
72
+ # },
73
+ # })
74
+ # @param attributes [Hash{String, Symbol => String}] the new attributes.
75
+ # @return [self] the updated mailing delivery.
76
+ # @api public
77
+ def update(attributes = {})
78
+ load_attributes(Core::RestApi.instance.put(path, attributes, if_match_header))
79
+ end
80
+
81
+ def reload
82
+ load_attributes(Core::RestApi.instance.get(path))
83
+ end
84
+
85
+ private
86
+
87
+ def path
88
+ ['mailings', mailing_id, 'mailing_deliveries', id].compact.join('/')
89
+ end
90
+
91
+ def if_match_header
92
+ {'If-Match' => self['version']}
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,63 @@
1
+ module Crm
2
+ # MailingRecipient represents a mailing recipient email address.
3
+ # @api public
4
+ class MailingRecipient < Core::BasicResource
5
+ include Core::Mixins::Inspectable
6
+ inspectable :id, :active, :consent, :topic_names
7
+
8
+ # Returns the requested mailing recipient.
9
+ # @example
10
+ # r = Crm::MailingRecipient.find("abc@example.com")
11
+ # r.active
12
+ # # => true
13
+ # r.consent
14
+ # # => "unknown"
15
+ # r.consent_given_at
16
+ # # => nil
17
+ # r.consent_revoked_at
18
+ # # => nil
19
+ # r.complained_at
20
+ # # => nil
21
+ # r.permanent_bounced_at
22
+ # # => nil
23
+ # r.topic_names
24
+ # # => ["foo"]
25
+ # r.topic_names_unsubscribed
26
+ # # => ["bar", "baz"]
27
+ # r.consent_logs
28
+ # # => [
29
+ # {
30
+ # "at"=>"2018-06-20T13:13:32Z",
31
+ # "description"=>"edited by API2 user root: this is the reason",
32
+ # "changes"=>{"active"=>["false", "true"]
33
+ # }
34
+ # ]
35
+ # @param email [String] the email address
36
+ # @return [MailingRecipient]
37
+ # @api public
38
+ def self.find(email)
39
+ if email.blank?
40
+ raise Crm::Errors::ResourceNotFound.new("Items could not be found.", [email])
41
+ end
42
+ new({'id' => email}).reload
43
+ end
44
+
45
+ # Updates the attributes of this mailing recipient.
46
+ # @example
47
+ # mailing_recipient.update({
48
+ # consent: "given",
49
+ # topic_names: ["foo", "bar"],
50
+ # edit_reason: "user registered on www.example.com and confirmed the double opt-in email link",
51
+ # })
52
+ # mailing_recipient.update({
53
+ # consent: "revoked",
54
+ # edit_reason: "user unsubscribed using our newsletter form on www.example.com",
55
+ # })
56
+ # @param attributes [Hash{String, Symbol => String}] the new attributes.
57
+ # @return [self] the updated mailing recipient.
58
+ # @api public
59
+ def update(attributes = {})
60
+ load_attributes(Core::RestApi.instance.put(path, attributes, if_match_header))
61
+ end
62
+ end
63
+ end
@@ -66,11 +66,10 @@ module Crm
66
66
  # @!parse extend Core::Mixins::Modifiable::ClassMethods
67
67
 
68
68
  # Returns all types.
69
- # @param include_deleted [Boolean] whether to include deleted types. Default: +false+.
70
69
  # @return [Array<Type>]
71
70
  # @api public
72
- def self.all(include_deleted: false)
73
- Core::RestApi.instance.get('types', { include_deleted: include_deleted }).map do |item|
71
+ def self.all
72
+ Core::RestApi.instance.get('types').map do |item|
74
73
  new(item)
75
74
  end
76
75
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_webcrm_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Infopark AG
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.0'
34
34
  type: :runtime
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: '4.0'
41
41
  - !ruby/object:Gem::Dependency
@@ -119,6 +119,8 @@ files:
119
119
  - lib/crm/event.rb
120
120
  - lib/crm/event_contact.rb
121
121
  - lib/crm/mailing.rb
122
+ - lib/crm/mailing_delivery.rb
123
+ - lib/crm/mailing_recipient.rb
122
124
  - lib/crm/template_set.rb
123
125
  - lib/crm/type.rb
124
126
  - lib/infopark_webcrm_sdk.rb
@@ -126,7 +128,7 @@ homepage: https://github.com/infopark/webcrm_sdk
126
128
  licenses:
127
129
  - LGPL-3.0
128
130
  metadata: {}
129
- post_install_message:
131
+ post_install_message:
130
132
  rdoc_options: []
131
133
  require_paths:
132
134
  - lib
@@ -141,10 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
143
  - !ruby/object:Gem::Version
142
144
  version: '0'
143
145
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.2.2
146
- signing_key:
146
+ rubygems_version: 3.0.3
147
+ signing_key:
147
148
  specification_version: 4
148
149
  summary: Infopark WebCRM SDK
149
150
  test_files: []
150
- has_rdoc: