shaf_client 0.2.1 → 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
  SHA256:
3
- metadata.gz: 00d873dd4459410cc9e81ea17ffa5feddd9323e085d362f889004285225adc6b
4
- data.tar.gz: d3e9f0ee21bd8e13a4f96a2294bef1f4a205f1662851c9d6abac2ddfb758ef8b
3
+ metadata.gz: 7fdd37c57d1bf069216445f7aacbb04e50aa451bd91a0512f21733aa22b030d2
4
+ data.tar.gz: 423457d2aa3cd2d79c959488f70ba9a4f454b5a2ce8887fc34377d7613223b0f
5
5
  SHA512:
6
- metadata.gz: 69d97383a3a53c5844a54876c8a99841a52bc211807112898d416fd9a319b9e408de9b600334c6b52e8152ffde07c16d266d6e9957737865c00c7dcf02ee3955
7
- data.tar.gz: a2ac7be354834908fc734c40414614998a5bcc4df5026d3b9ddc1e2686dba3352a35bfc20bc57895055896454eae62345c91b33beda7b5afe4f4b8ab53b14ed1
6
+ metadata.gz: 77716b275f965a5f9ae1c5753497bcd5590d5e1250cd0b4241783f8bb874597b42a4ed840ad32d9945313cd64a9366294b015b7825b15aaa208aba8430e8232e
7
+ data.tar.gz: a110d1773f71aa7d4d71aa04cc702e26a462df87116bd29339c5fbd60d3af001992a968493bbaeaecd5fc731931cc25ede2e2ae72f7da9bde867d3a60a307a66
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/shaf_client.rb CHANGED
@@ -47,7 +47,7 @@ class ShafClient
47
47
  payload: payload,
48
48
  opts: options
49
49
  )
50
- Resource.new(self, response.body, response.status, response.headers)
50
+ Resource.build(self, response.body, response.status, response.headers)
51
51
  end
52
52
  end
53
53
 
@@ -4,6 +4,8 @@ require 'shaf_client/link'
4
4
  class ShafClient
5
5
  class Form < Resource
6
6
 
7
+ profile 'shaf-form'
8
+
7
9
  def values
8
10
  return @values if defined? @values
9
11
 
@@ -5,7 +5,32 @@ class ShafClient
5
5
  class Resource < BaseResource
6
6
  attr_reader :http_status, :headers
7
7
 
8
- def initialize(client, payload, status = nil, headers = nil)
8
+ class ResourceClasses
9
+ class << self
10
+ def all
11
+ @all ||= Hash.new(Resource)
12
+ end
13
+
14
+ def for(name)
15
+ all[name]
16
+ end
17
+
18
+ def set(name, clazz)
19
+ all[name] = clazz
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.profile(name)
25
+ ResourceClasses.set(name, self)
26
+ end
27
+
28
+ def self.build(client, payload, status = nil, headers = {})
29
+ profile = headers.fetch('content-type', '')[/profile=([\w-]+)/, 1]
30
+ ResourceClasses.for(profile).new(client, payload, status, headers)
31
+ end
32
+
33
+ def initialize(client, payload, status = nil, headers = {})
9
34
  @client = client
10
35
  @http_status = status
11
36
  @headers = headers
@@ -15,8 +40,7 @@ class ShafClient
15
40
  %i[get put post delete patch get_form].each do |method|
16
41
  define_method(method) do |rel, payload = nil, **options|
17
42
  href = link(rel).href
18
- args = [method, href]
19
- client.send(*args, payload: payload, **options)
43
+ client.send(method, href, payload: payload, **options)
20
44
  end
21
45
  end
22
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shaf_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sammy Henningsson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  ZMhjYR7sRczGJx+GxGU2EaR0bjRsPVlC4ywtFxoOfRG3WaJcpWGEoAoMJX6Z0bRv
31
31
  M40=
32
32
  -----END CERTIFICATE-----
33
- date: 2019-02-10 00:00:00.000000000 Z
33
+ date: 2019-03-25 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: faraday
metadata.gz.sig CHANGED
Binary file