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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f51e5197d44b448205a29b9c253290619142581c
4
- data.tar.gz: 2a27f4873b5c1b9348375c244bfef7e923cff04a
2
+ SHA256:
3
+ metadata.gz: de5ee14889bf953e416b87030e72390494e1d054d3741bda1583cdafdb233577
4
+ data.tar.gz: 7b462a2aedf9b630ceee7c602e42fa81015218b005afc3242f2c85b22e30a48d
5
5
  SHA512:
6
- metadata.gz: 542365f59c405828a792cd50832735ed98cebdd82b77ccdfd4e5ad99b4a0a39f1441e6d72f0f282f3c8a37aa58a8741b556b31f7fe244d8f3fc70a6760f110fe
7
- data.tar.gz: bb6175189fbe0abcc532b9c2c623c96788b97e0bd4a089f580927a6a9935efdd30600dce459c74cffc76a3749fbe0e2be6a131746a0902edcff5caec3a41fcf9
6
+ metadata.gz: a4871a86d2ef4c2bb7952966553c90b79f36ab1a2467e9da120bea156a5c30ac08c23f609ce5fd27426d6f434aac9cc96c7ace9998fa6cefaebfca8011cea58a
7
+ data.tar.gz: ad3eac246d498eedf109bbb024c28b97982215055d1e31b247e92a6df08462ccbc08d8d2c6114fc24ee4a94c90cb21c0cace29c9be9f249b1f47167dae7ab1e7
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'excon'
2
4
 
3
5
  require 'girlscout/resource'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GirlScout
2
4
  class Attachment < GirlScout::Object
3
5
  end
@@ -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 respond_to?(method_name, include_all=false)
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 = attr || @attributes
40
+ attr ||= @attributes
39
41
  attr = attr.attributes if attr.respond_to?(:attributes)
40
42
 
41
- attr.inject({}) do |hash,(k,v)|
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
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GirlScout
2
4
  module Concerns
3
5
  module HasResource
@@ -33,4 +35,3 @@ module GirlScout
33
35
  end
34
36
  end
35
37
  end
36
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GirlScout
2
4
  DEFAULT_API_PREFIX = 'https://api.helpscout.net/v1'
3
5
 
@@ -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["item"])
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["reload"] ||= true
13
- Conversation.new(resource.post(payload: attributes)["item"])
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["customer"] || {})
20
+ @customer ||= Customer.new(self['customer'] || {})
19
21
  end
20
22
 
21
23
  def threads
22
- @threads ||= (self["threads"] || []).map { |attr| Thread.new(attr) }
24
+ @threads ||= (self['threads'] || []).map { |attr| Thread.new(attr) }
23
25
  end
24
26
 
25
27
  def mailbox
26
- @mailbox ||= Mailbox.new(self["mailbox"] || {})
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["customer"] = customer.as_json if key?("customer")
33
- json["threads"] = threads.map(&:as_json) if key?("threads")
34
- json["mailbox"] = mailbox.as_json if key?("mailbox")
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
@@ -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["item"])
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["type"] = "customer"
19
+ json['type'] = 'customer'
18
20
  json
19
21
  end
20
22
  end
@@ -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["error"]
9
+ super @attributes['error']
8
10
  end
9
11
  end
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GirlScout
2
4
  class Folder < GirlScout::Object
3
5
  end
@@ -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
- alias_method :size, :count
7
- alias_method :length, :count
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["items"] || []).map do |attr|
17
+ @items ||= (@attributes['items'] || []).map do |attr|
16
18
  @item_class.new(attr)
17
19
  end
18
20
  end
@@ -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["item"])
13
+ Mailbox.new(resource["/#{id}"].get['item'])
12
14
  end
13
15
  end
14
16
 
@@ -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
@@ -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 = [:get, :put, :post, :patch, :delete]
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, &block|
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]["Content-Type"] = "application/json"
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 400 <= response.status && response.status < 600
39
- raise GirlScout::Error.new(JSON.parse(response.body))
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GirlScout
2
4
  class Search < GirlScout::Object
3
5
  endpoint '/search'
@@ -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["attachments"] || []).map { |attr| Attachment.new(attr) }
6
+ @attachments ||= (self['attachments'] || []).map do |attr|
7
+ Attachment.new(attr)
8
+ end
5
9
  end
6
10
 
7
11
  def created_by
8
- return @created_by if defined? @created_by and @created_by
12
+ @created_by = nil unless defined? @created_by
13
+ return @created_by if @created_by
9
14
 
10
- attr = @attributes["createdBy"]
11
- creator_type = "GirlScout::#{attr["type"].capitalize}".constantize rescue User
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["createdBy"] = created_by.as_json if key?("created_by")
26
+ json['createdBy'] = created_by.as_json if key?('created_by')
18
27
  json
19
28
  end
20
29
  end
@@ -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["item"])
13
+ User.new(resource["/#{id}"].get['item'])
12
14
  end
13
15
 
14
16
  def me
15
- find("me")
17
+ find('me')
16
18
  end
17
19
  end
18
20
 
19
21
  def as_json
20
22
  json = super
21
- json["type"] = "user"
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.3.3
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.49'
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.49'
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.8'
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.8'
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.12'
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.12'
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.9'
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: '5.9'
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.10'
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.10'
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: '11.2'
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: '11.2'
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: '3.0'
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: '3.0'
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.5.1
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.