girlscout 0.2.3 → 0.3.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
2
  SHA1:
3
- metadata.gz: 7757794a46770a9c9dc9a2069da1a142915b81ad
4
- data.tar.gz: f0ac94f3c3bce9cfd3e617f09eff0927c9fd4bce
3
+ metadata.gz: 9ccc0c560938afb43d3438904fa99f116cb366d0
4
+ data.tar.gz: 0a60b0d92d6ffe2b91e5a28b1ac0a55068d8fbf3
5
5
  SHA512:
6
- metadata.gz: 57866d8cdc3c564aa52fa688d583495e462452283d3575c1a3e57b7f5a8deca58aba4f5819b17198c12daa4521e10f18a0cdf9e0ce29ad7008c0eefd4010fab6
7
- data.tar.gz: 9d80473c624041b0280cfc8074c322cbdf6cd0f3b1508ba0c7a7a512a3e2d3be692c749d45d27e983b754a5544485b651cd3e897cda048e955199ae593ee5c84
6
+ metadata.gz: eb33333214ed4f1ba9732220d444d48242be7931019237ca2d3d62d74780e27bc1d2f2417b6456376bad4f55ca764a3632fca46e870578c090859dd8a1d264ec
7
+ data.tar.gz: d1d0a9c6af2aef765e0152938941f9d533a42a67681b4b1a063dcae9ee4516e6071a38ecabe7c1aba8743dd8a457384122ea5e8924fe7e242cfee6b63887deab
@@ -6,6 +6,7 @@ require 'girlscout/config'
6
6
  require 'girlscout/concerns/has_attributes'
7
7
  require 'girlscout/concerns/has_resource'
8
8
  require 'girlscout/object'
9
+ require 'girlscout/error'
9
10
 
10
11
  require 'girlscout/list'
11
12
  require 'girlscout/folder'
@@ -34,6 +34,16 @@ module GirlScout
34
34
 
35
35
  protected
36
36
 
37
+ def normalize_attributes(attr)
38
+ attr = attr || @attributes
39
+ attr = attr.attributes if attr.respond_to?(:attributes)
40
+
41
+ attr.inject({}) do |hash,(k,v)|
42
+ hash[attr_key(k)] = v
43
+ hash
44
+ end
45
+ end
46
+
37
47
  def attr_key(sym)
38
48
  parts = sym.to_s.split('_') # camelize w/o active support
39
49
  parts[0] + parts[1..-1].map(&:capitalize).join('')
@@ -0,0 +1,10 @@
1
+ module GirlScout
2
+ class Error < ::StandardError
3
+ include GirlScout::Concerns::HasAttributes
4
+
5
+ def initialize(attr={})
6
+ @attributes = normalize_attributes(attr)
7
+ super @attributes["error"]
8
+ end
9
+ end
10
+ end
@@ -4,13 +4,7 @@ module GirlScout
4
4
  include GirlScout::Concerns::HasResource
5
5
 
6
6
  def initialize(attr={}, options={})
7
- attr = attr.attributes if attr.is_a?(Object)
8
- attr = attr.inject({}) do |hash,(k,v)|
9
- hash[attr_key(k)] = v
10
- hash
11
- end
12
-
13
- @attributes = attr
7
+ @attributes = normalize_attributes(attr)
14
8
  @resource = options[:resource] if options[:resource]
15
9
  end
16
10
  end
@@ -34,22 +34,13 @@ module GirlScout
34
34
 
35
35
  def request(options={})
36
36
  auth = { user: Config.api_key, password: 'X' }
37
- JSON.parse(Excon.new(url, auth).request(options).body)
38
- end
39
-
40
- # def get(query=nil)
41
- # opts = { }
42
- # opts[:headers] = { params: query } if query
43
-
44
- # parse(rest_resource.get(opts))
45
- # end
37
+ response = Excon.new(url, auth).request(options)
38
+ if response.status != 200
39
+ raise GirlScout::Error.new(JSON.parse(response.body))
40
+ end
46
41
 
47
- # [:put, :post, :patch, :delete].each do |method|
48
- # define_method(method.to_s) do |payload=nil|
49
- # payload = serialize(payload) if payload
50
- # parse(rest_resource.send(method, payload, content_type: :json))
51
- # end
52
- # end
42
+ JSON.parse(response.body)
43
+ end
53
44
 
54
45
  private
55
46
 
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.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chakrit Wichian
@@ -163,6 +163,7 @@ files:
163
163
  - lib/girlscout/config.rb
164
164
  - lib/girlscout/conversation.rb
165
165
  - lib/girlscout/customer.rb
166
+ - lib/girlscout/error.rb
166
167
  - lib/girlscout/folder.rb
167
168
  - lib/girlscout/list.rb
168
169
  - lib/girlscout/mailbox.rb