shyftplan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4f23944868ffa1c4dece4e0c82d639f4b0aaf0ee90ebcdaef42df53d0b72a9db
4
+ data.tar.gz: aa143c295b5d78b8374ad46039e3c2e9e34b10c8447a0a52443a1cd25f3d02fc
5
+ SHA512:
6
+ metadata.gz: 109ac9a53bb546bb6293ffc330cfa5bbdd30915d8c77318c839c91b9aad30da01887f284a6d3d5147481cb3a2093f251c73f1e6f3e80aef0b340b223566fbdfd
7
+ data.tar.gz: 117457bce38c2b53cf8d172256c8912aa085d6a07fd480ce8cd9cfc1df20b134d251eafe033c0da79f247c443a9e36ed3a1089403de0b5ec6466534994b8a320
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # shyftplan-ruby
2
+
3
+ Ruby gem for Shyftplan's REST API https://github.com/shyftplan/api-documentation
4
+
5
+ Try the gem on repl.it https://replit.com/@nisanth074/tryshyftplanruby#main.rb
6
+
7
+ ## Installation
8
+
9
+ Add the gem to your Rails app's Gemfile
10
+
11
+ ```ruby
12
+ gem "shyftplan", git: "https://github.com/nisanth074/shyftplan-ruby", branch: "main"
13
+ ```
14
+
15
+ and bundle install
16
+
17
+ ```bash
18
+ bundle install
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Initialize the Shyftplan client
24
+
25
+ ```ruby
26
+ shyftplan = Shyftplan.new("john@acme.com", "dummy_api_token")
27
+ ```
28
+
29
+ Retrieve evaluations
30
+
31
+ ```ruby
32
+ response = shyftplan.get("/evaluations")
33
+ evaluations = response["items"]
34
+ ```
35
+
36
+ Retrieve evaluations across all pages
37
+
38
+ ```ruby
39
+ evaluations = shyftplan.each_page("/evaluations")
40
+ ```
41
+
42
+ Doing the above may take a while. If you'd like to perform any action after each page retrieval, provide a block
43
+
44
+ ```ruby
45
+ shyftplan.each_page("/evaluations") do |page|
46
+ puts "Page retrieved..."
47
+
48
+ evaluations = page["items"]
49
+ EvaluationsCSVExport.add(evaluations)
50
+ end
51
+ ```
52
+
53
+ ## Todos
54
+
55
+ - Publish gem to https://rubygems.org
@@ -0,0 +1,11 @@
1
+ class Shyftplan
2
+ module Errors
3
+ class UnsuccessfulResponse < StandardError
4
+ attr_reader :response
5
+
6
+ def initialize(response)
7
+ @response = response
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class Page
2
+ class << self
3
+ def retrieve(*args)
4
+ end
5
+ end
6
+
7
+ def initialize(shyftplan, path, page_number, per_page, options = {})
8
+ @shyftplan = shyftplan
9
+ end
10
+
11
+ def retrieve
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class Shyftplan
2
+ VERSION = "0.1.0"
3
+ end
data/lib/shyftplan.rb ADDED
@@ -0,0 +1,92 @@
1
+ require "httparty"
2
+ require_relative "./shyftplan/version"
3
+ require_relative "./shyftplan/errors"
4
+
5
+ class Shyftplan
6
+ attr_reader :site,
7
+ :user_email,
8
+ :authentication_token
9
+
10
+ def initialize(*args)
11
+ if args.size == 3
12
+ @site, @user_email, @authentication_token = args
13
+ else
14
+ @site = "https://shyftplan.com"
15
+ @user_email, @authentication_token = args
16
+ end
17
+ end
18
+
19
+ def base_url
20
+ site + "/api/v1"
21
+ end
22
+
23
+ [:get, :post, :put, :delete].each do |http_method|
24
+ define_method(http_method) do |*args|
25
+ request(http_method, *args)
26
+ end
27
+ end
28
+
29
+ # Retrieve items across all pages
30
+ # @example
31
+ # Shyftplan.each_page("/shifts")
32
+ #
33
+ # @example Perform an action after each page retrieval
34
+ # Shyftplan.each_page("/shifts") { |page| puts "Page retrieved..." }
35
+ def each_page(path, options = {})
36
+ page = 1
37
+ items = []
38
+ loop do
39
+ options[:query] = if options[:query]
40
+ options[:query].merge(page:)
41
+ else
42
+ {
43
+ page:,
44
+ }
45
+ end
46
+ response = get(path, options)
47
+ yield response if block_given?
48
+ page = page + 1
49
+ items = items + response["items"]
50
+ break if items.size >= response["total"]
51
+ end
52
+
53
+ items
54
+ end
55
+
56
+ private
57
+
58
+ def request(http_method, path, options = {})
59
+ url = base_url + path
60
+ httparty_options = default_httparty_options
61
+ httparty_options[:query].merge!(options[:query]) if options[:query]
62
+ if options[:body]
63
+ httparty_options[:body] = if options[:body].is_a?(String)
64
+ options[:body]
65
+ else
66
+ options[:body].to_json
67
+ end
68
+ httparty_options[:headers]["Content-Type"] = "application/json"
69
+ end
70
+ response = HTTParty.public_send(http_method, url, httparty_options)
71
+ raise Shyftplan::Errors::UnsuccessfulResponse.new(response) unless response.success?
72
+ response
73
+ end
74
+
75
+ def default_httparty_options
76
+ {
77
+ headers: default_headers,
78
+ query: authentication_params
79
+ }
80
+ end
81
+
82
+ def authentication_params
83
+ {
84
+ user_email:,
85
+ authentication_token:
86
+ }
87
+ end
88
+
89
+ def default_headers
90
+ { "Accept" => "application/json" }
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shyftplan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nisanth Chunduru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_bot
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby gem for Shyftplan's REST API
98
+ email:
99
+ - nisanth074@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - README.md
105
+ - lib/shyftplan.rb
106
+ - lib/shyftplan/errors.rb
107
+ - lib/shyftplan/page.rb
108
+ - lib/shyftplan/version.rb
109
+ homepage: https://github.com/nisanth074/shyftplan-ruby
110
+ licenses: []
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.4.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Ruby gem for Shyftplan's REST API
131
+ test_files: []