girlscout 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/girlscout.rb +2 -0
- data/lib/girlscout/attachment.rb +2 -0
- data/lib/girlscout/concerns/has_attributes.rb +5 -5
- data/lib/girlscout/concerns/has_resource.rb +2 -1
- data/lib/girlscout/config.rb +2 -0
- data/lib/girlscout/conversation.rb +11 -9
- data/lib/girlscout/customer.rb +4 -2
- data/lib/girlscout/error.rb +4 -2
- data/lib/girlscout/folder.rb +2 -0
- data/lib/girlscout/list.rb +5 -3
- data/lib/girlscout/mailbox.rb +3 -1
- data/lib/girlscout/object.rb +3 -1
- data/lib/girlscout/resource.rb +10 -23
- data/lib/girlscout/search.rb +2 -0
- data/lib/girlscout/thread.rb +14 -5
- data/lib/girlscout/user.rb +5 -3
- metadata +58 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de5ee14889bf953e416b87030e72390494e1d054d3741bda1583cdafdb233577
|
4
|
+
data.tar.gz: 7b462a2aedf9b630ceee7c602e42fa81015218b005afc3242f2c85b22e30a48d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4871a86d2ef4c2bb7952966553c90b79f36ab1a2467e9da120bea156a5c30ac08c23f609ce5fd27426d6f434aac9cc96c7ace9998fa6cefaebfca8011cea58a
|
7
|
+
data.tar.gz: ad3eac246d498eedf109bbb024c28b97982215055d1e31b247e92a6df08462ccbc08d8d2c6114fc24ee4a94c90cb21c0cace29c9be9f249b1f47167dae7ab1e7
|
data/lib/girlscout.rb
CHANGED
data/lib/girlscout/attachment.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
module Concerns
|
3
5
|
module HasAttributes
|
@@ -21,7 +23,7 @@ module GirlScout
|
|
21
23
|
@attributes.key?(attr_key(key))
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
26
|
+
def respond_to_missing?(method_name, include_all = false)
|
25
27
|
key?(method_name) || super
|
26
28
|
end
|
27
29
|
|
@@ -35,12 +37,11 @@ module GirlScout
|
|
35
37
|
protected
|
36
38
|
|
37
39
|
def normalize_attributes(attr)
|
38
|
-
attr
|
40
|
+
attr ||= @attributes
|
39
41
|
attr = attr.attributes if attr.respond_to?(:attributes)
|
40
42
|
|
41
|
-
attr.
|
43
|
+
attr.each_with_object({}) do |(k, v), hash|
|
42
44
|
hash[attr_key(k)] = v
|
43
|
-
hash
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -51,4 +52,3 @@ module GirlScout
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
54
|
-
|
data/lib/girlscout/config.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
class Conversation < GirlScout::Object
|
3
5
|
endpoint '/conversations'
|
4
6
|
|
5
7
|
class << self
|
6
8
|
def find(id)
|
7
|
-
Conversation.new(resource["/#{id}"].get[
|
9
|
+
Conversation.new(resource["/#{id}"].get['item'])
|
8
10
|
end
|
9
11
|
|
10
12
|
def create(attributes)
|
11
13
|
attributes = attributes.as_json if attributes.respond_to?(:as_json)
|
12
|
-
attributes[
|
13
|
-
Conversation.new(resource.post(payload: attributes)[
|
14
|
+
attributes['reload'] ||= true
|
15
|
+
Conversation.new(resource.post(payload: attributes)['item'])
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def customer
|
18
|
-
@customer ||= Customer.new(self[
|
20
|
+
@customer ||= Customer.new(self['customer'] || {})
|
19
21
|
end
|
20
22
|
|
21
23
|
def threads
|
22
|
-
@threads ||= (self[
|
24
|
+
@threads ||= (self['threads'] || []).map { |attr| Thread.new(attr) }
|
23
25
|
end
|
24
26
|
|
25
27
|
def mailbox
|
26
|
-
@mailbox ||= Mailbox.new(self[
|
28
|
+
@mailbox ||= Mailbox.new(self['mailbox'] || {})
|
27
29
|
end
|
28
30
|
|
29
31
|
def as_json
|
30
32
|
# TODO: Test
|
31
33
|
json = super.dup
|
32
|
-
json[
|
33
|
-
json[
|
34
|
-
json[
|
34
|
+
json['customer'] = customer.as_json if key?('customer')
|
35
|
+
json['threads'] = threads.map(&:as_json) if key?('threads')
|
36
|
+
json['mailbox'] = mailbox.as_json if key?('mailbox')
|
35
37
|
json
|
36
38
|
end
|
37
39
|
end
|
data/lib/girlscout/customer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
class Customer < GirlScout::Object
|
3
5
|
endpoint '/customers'
|
@@ -8,13 +10,13 @@ module GirlScout
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def find(id)
|
11
|
-
Customer.new(resource["/#{id}"].get[
|
13
|
+
Customer.new(resource["/#{id}"].get['item'])
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
17
|
def as_json
|
16
18
|
json = super
|
17
|
-
json[
|
19
|
+
json['type'] = 'customer'
|
18
20
|
json
|
19
21
|
end
|
20
22
|
end
|
data/lib/girlscout/error.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
class Error < ::StandardError
|
3
5
|
include GirlScout::Concerns::HasAttributes
|
4
6
|
|
5
|
-
def initialize(attr={})
|
7
|
+
def initialize(attr = {})
|
6
8
|
@attributes = normalize_attributes(attr)
|
7
|
-
super @attributes[
|
9
|
+
super @attributes['error']
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
data/lib/girlscout/folder.rb
CHANGED
data/lib/girlscout/list.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
class List < GirlScout::Object
|
3
5
|
include Enumerable
|
4
6
|
|
5
7
|
attr_accessor :item_class
|
6
|
-
|
7
|
-
|
8
|
+
alias size count
|
9
|
+
alias length count
|
8
10
|
|
9
11
|
def initialize(attr, item_class)
|
10
12
|
super(attr)
|
@@ -12,7 +14,7 @@ module GirlScout
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def items
|
15
|
-
@items ||= (@attributes[
|
17
|
+
@items ||= (@attributes['items'] || []).map do |attr|
|
16
18
|
@item_class.new(attr)
|
17
19
|
end
|
18
20
|
end
|
data/lib/girlscout/mailbox.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
class Mailbox < GirlScout::Object
|
3
5
|
endpoint '/mailboxes'
|
@@ -8,7 +10,7 @@ module GirlScout
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def find(id)
|
11
|
-
Mailbox.new(resource["/#{id}"].get[
|
13
|
+
Mailbox.new(resource["/#{id}"].get['item'])
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
data/lib/girlscout/object.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
class Object
|
3
5
|
include GirlScout::Concerns::HasAttributes
|
4
6
|
include GirlScout::Concerns::HasResource
|
5
7
|
|
6
|
-
def initialize(attr={}, options={})
|
8
|
+
def initialize(attr = {}, options = {})
|
7
9
|
@attributes = normalize_attributes(attr)
|
8
10
|
@resource = options[:resource] if options[:resource]
|
9
11
|
end
|
data/lib/girlscout/resource.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
|
3
5
|
module GirlScout
|
4
6
|
class Resource
|
5
|
-
METHODS = [
|
7
|
+
METHODS = %i[get put post patch delete].freeze
|
6
8
|
|
7
|
-
def initialize(url:
|
9
|
+
def initialize(url: '')
|
8
10
|
@url = url
|
9
11
|
end
|
10
12
|
|
@@ -17,42 +19,27 @@ module GirlScout
|
|
17
19
|
end
|
18
20
|
|
19
21
|
METHODS.each do |method|
|
20
|
-
define_method(method) do |payload: nil, query: nil
|
22
|
+
define_method(method) do |payload: nil, query: nil|
|
21
23
|
options = { method: method }
|
22
24
|
if payload
|
23
25
|
options[:body] = JSON.generate(payload)
|
24
26
|
options[:headers] ||= {}
|
25
|
-
options[:headers][
|
26
|
-
end
|
27
|
-
if query
|
28
|
-
options[:query] = query
|
27
|
+
options[:headers]['Content-Type'] = 'application/json'
|
29
28
|
end
|
29
|
+
options[:query] = query if query
|
30
30
|
|
31
31
|
request(options)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def request(options={})
|
35
|
+
def request(options = {})
|
36
36
|
auth = { user: Config.api_key, password: 'X' }
|
37
37
|
response = Excon.new(url, auth).request(options)
|
38
|
-
if
|
39
|
-
raise GirlScout::Error
|
38
|
+
if response.status >= 400 && response.status < 600
|
39
|
+
raise GirlScout::Error, JSON.parse(response.body)
|
40
40
|
end
|
41
41
|
|
42
42
|
JSON.parse(response.body)
|
43
43
|
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def parse(response)
|
48
|
-
JSON.load(response)
|
49
|
-
end
|
50
|
-
|
51
|
-
def serialize(payload)
|
52
|
-
payload.to_json
|
53
|
-
end
|
54
|
-
|
55
|
-
def call
|
56
|
-
end
|
57
44
|
end
|
58
45
|
end
|
data/lib/girlscout/search.rb
CHANGED
data/lib/girlscout/thread.rb
CHANGED
@@ -1,20 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
class Thread < GirlScout::Object
|
3
5
|
def attachments
|
4
|
-
@attachments ||= (self[
|
6
|
+
@attachments ||= (self['attachments'] || []).map do |attr|
|
7
|
+
Attachment.new(attr)
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
11
|
def created_by
|
8
|
-
|
12
|
+
@created_by = nil unless defined? @created_by
|
13
|
+
return @created_by if @created_by
|
9
14
|
|
10
|
-
attr = @attributes[
|
11
|
-
creator_type =
|
15
|
+
attr = @attributes['createdBy']
|
16
|
+
creator_type = begin
|
17
|
+
"GirlScout::#{attr['type'].capitalize}".constantize
|
18
|
+
rescue StandardError
|
19
|
+
User
|
20
|
+
end
|
12
21
|
@created_by ||= creator_type.new(attr)
|
13
22
|
end
|
14
23
|
|
15
24
|
def as_json
|
16
25
|
json = super
|
17
|
-
json[
|
26
|
+
json['createdBy'] = created_by.as_json if key?('created_by')
|
18
27
|
json
|
19
28
|
end
|
20
29
|
end
|
data/lib/girlscout/user.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GirlScout
|
2
4
|
class User < GirlScout::Object
|
3
5
|
endpoint '/users'
|
@@ -8,17 +10,17 @@ module GirlScout
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def find(id)
|
11
|
-
User.new(resource["/#{id}"].get[
|
13
|
+
User.new(resource["/#{id}"].get['item'])
|
12
14
|
end
|
13
15
|
|
14
16
|
def me
|
15
|
-
find(
|
17
|
+
find('me')
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
21
|
def as_json
|
20
22
|
json = super
|
21
|
-
json[
|
23
|
+
json['type'] = 'user'
|
22
24
|
json
|
23
25
|
end
|
24
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: girlscout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chakrit Wichian
|
@@ -16,56 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.62'
|
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
|
-
version: '0.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: faraday
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.9'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.9'
|
26
|
+
version: '0.62'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: json
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1
|
33
|
+
version: '2.1'
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1
|
40
|
+
version: '2.1'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
47
|
+
version: '1.16'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
54
|
+
version: '1.16'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: guard
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,56 +86,98 @@ dependencies:
|
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '5.
|
89
|
+
version: '5.11'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.11'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-reporters
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '1.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: overcommit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.46'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.46'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: pry
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0.
|
131
|
+
version: '0.11'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0.
|
138
|
+
version: '0.11'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rake
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - "~>"
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '12.3'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '12.3'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.58'
|
132
160
|
type: :development
|
133
161
|
prerelease: false
|
134
162
|
version_requirements: !ruby/object:Gem::Requirement
|
135
163
|
requirements:
|
136
164
|
- - "~>"
|
137
165
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
166
|
+
version: '0.58'
|
139
167
|
- !ruby/object:Gem::Dependency
|
140
168
|
name: vcr
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
142
170
|
requirements:
|
143
171
|
- - "~>"
|
144
172
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
173
|
+
version: '4.0'
|
146
174
|
type: :development
|
147
175
|
prerelease: false
|
148
176
|
version_requirements: !ruby/object:Gem::Requirement
|
149
177
|
requirements:
|
150
178
|
- - "~>"
|
151
179
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
180
|
+
version: '4.0'
|
153
181
|
description: Provides integration with HelpScout REST API.
|
154
182
|
email: chakrit@omise.co
|
155
183
|
executables: []
|
@@ -192,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
220
|
version: '0'
|
193
221
|
requirements: []
|
194
222
|
rubyforge_project:
|
195
|
-
rubygems_version: 2.
|
223
|
+
rubygems_version: 2.7.7
|
196
224
|
signing_key:
|
197
225
|
specification_version: 4
|
198
226
|
summary: Integrate your support tooling with HelpScout API.
|