breathe 0.1.2 → 0.1.3

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: a0603fe16b7652a523413e6d25e2384d25c7b24fa019a06f01faf942d2867251
4
- data.tar.gz: a37a9df471df6171b84191114eb773ced11517062e47ab9c109225293fdc4a20
3
+ metadata.gz: b556ec113d7d5c5f9666a7107c86707b4aa28bec7932eb7607c090631c07250c
4
+ data.tar.gz: c5b26bce036fd4324e154b0df6e68e10c94e441691e015bb2bb9cd5ac702dc52
5
5
  SHA512:
6
- metadata.gz: 913153ddc8209455f3823f3b76dc0d8abdf71d0d829cda670de37ca961d2320dc852ea44d316785034a32475bd07021b296447375ffe153af863c3bdf8ab6830
7
- data.tar.gz: 1b907623d421d6c92a76f54b00a2ea76634eb133542aa64dba0a9a7a00af944019df0f0d18645a8921a2127ccfbb1554eb6a53d26d2c62a766f53d86141882fd
6
+ metadata.gz: f0af79e4598c36081ae9705f8b90bec086a54530a008644e4dbce0f7158094e32744d90f7f6677b232caa90cebd55851afaf31d4fe8bd9813b7d4471aa452ef6
7
+ data.tar.gz: 0fefc175a63493210d9c5c81e31b11539e5b08b77ac2e6d626285fdd7552846668cf2a4d670b2f59e742d71e48ffb0c65c6c7b799aaacc085a5887cca01e97f7
data/README.md CHANGED
@@ -39,7 +39,7 @@ client = Breathe::Client.new(api_key: YOUR_API_KEY)
39
39
  And use like so
40
40
 
41
41
  ```ruby
42
- client.absences
42
+ client.absences.list
43
43
  #=> [
44
44
  # {
45
45
  # "employee"=>{"id"=>123, "email"=>"someone@somewhere.com", "first_name"=>"Jo", "last_name"=>"Bloggs"},
@@ -62,6 +62,10 @@ client.absences
62
62
  # },
63
63
  # ...
64
64
  #]
65
+ client.absences.list.next_page
66
+ # 2
67
+ client.absences.list.per_page
68
+ # 100
65
69
  ```
66
70
 
67
71
  You can also pass in arguments like so:
@@ -2,6 +2,8 @@ require "faraday"
2
2
 
3
3
  require "breathe/version"
4
4
  require "breathe/client"
5
+ require "breathe/response"
6
+
5
7
  require "breathe/absences"
6
8
 
7
9
  module Breathe
@@ -7,14 +7,8 @@ module Breathe
7
7
  end
8
8
 
9
9
  def list(args = {})
10
- parse_response(client.get("absences", args))
11
- end
12
-
13
- private
14
-
15
- def parse_response(request)
16
- json = JSON.parse(request.body)
17
- json["absences"]
10
+ response = client.get("absences", args)
11
+ Response.new(response, "absences")
18
12
  end
19
13
  end
20
14
  end
@@ -0,0 +1,53 @@
1
+ module Breathe
2
+ class Response
3
+ extend Forwardable
4
+ attr_reader :data, :type, :response
5
+
6
+ delegate [:each, :find, :select, :count, :[]] => :body
7
+
8
+ def initialize(response, type)
9
+ @response = response
10
+ @data = JSON.parse(response.body)
11
+ @type = type
12
+ end
13
+
14
+ def total
15
+ response.headers["total"].to_i
16
+ end
17
+
18
+ def per_page
19
+ response.headers.per_page
20
+ end
21
+
22
+ def next_page
23
+ link_headers["next"].to_i unless link_headers.nil?
24
+ end
25
+
26
+ def last_page
27
+ link_headers["last"].to_i unless link_headers.nil?
28
+ end
29
+
30
+ private
31
+
32
+ def body
33
+ data[type]
34
+ end
35
+
36
+ def link_headers
37
+ @link_headers ||= begin
38
+ return nil if response.headers["link"].nil?
39
+
40
+ parse_link_headers(response.headers["link"])
41
+ end
42
+ end
43
+
44
+ def parse_link_headers(header)
45
+ header.split(",").map { |header|
46
+ v, k = header.split(";")
47
+ k = k.match("rel=\"(.+)\"")[1]
48
+ v = v.match("page=([0-9]+)")[1]
49
+ [k, v]
50
+ }.to_h
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Breathe
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breathe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Harrison
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-01 00:00:00.000000000 Z
11
+ date: 2019-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -160,6 +160,7 @@ files:
160
160
  - lib/breathe.rb
161
161
  - lib/breathe/absences.rb
162
162
  - lib/breathe/client.rb
163
+ - lib/breathe/response.rb
163
164
  - lib/breathe/version.rb
164
165
  homepage: http://github.com/dxw/breathe_ruby
165
166
  licenses: