karatekit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ module Karatekit
2
+
3
+ # Class for API Rate Limit info
4
+ #
5
+ # @!attribute [w] limit
6
+ # @return [Integer] Max tries per rate limit period
7
+ # @!attribute [w] remaining
8
+ # @return [Integer] Remaining tries per rate limit period
9
+ # @!attribute [w] resets_at
10
+ # @return [Time] Indicates when rate limit resets
11
+ # @!attribute [w] resets_in
12
+ # @return [Integer] Number of seconds when rate limit resets
13
+ #
14
+ # @see https://developer.github.com/v3/#rate-limiting
15
+ class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in)
16
+
17
+ # Get rate limit info from HTTP response
18
+ #
19
+ # @param response [#headers] HTTP response
20
+ # @return [RateLimit]
21
+ def self.from_response(response)
22
+ info = new
23
+ if response && !response.headers.nil?
24
+ info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i
25
+ info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i
26
+ info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i)
27
+ info.resets_in = [(info.resets_at - Time.now).to_i, 0].max
28
+ end
29
+
30
+ info
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+ require 'karatekit/error'
3
+
4
+ module Karatekit
5
+ # Faraday response middleware
6
+ module Response
7
+
8
+ # This class raises an Karatekit-flavored exception based
9
+ # HTTP status codes returned by the API
10
+ class RaiseError < Faraday::Response::Middleware
11
+
12
+ private
13
+
14
+ def on_complete(response)
15
+ if error = Karatekit::Error.from_response(response)
16
+ raise error
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Karatekit
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ module Karatekit
2
+
3
+ # Allows warnings to be suppressed via environment variable.
4
+ module Warnable
5
+
6
+ # Wrapper around Kernel#warn to print warnings unless
7
+ # OCTOKIT_SILENT is set to true.
8
+ #
9
+ # @return [nil]
10
+ def octokit_warn(*message)
11
+ unless ENV['OCTOKIT_SILENT']
12
+ warn message
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/karatekit.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'karatekit/client'
2
+ require 'karatekit/default'
3
+
4
+ # Ruby toolkit for the kampfsport.center API
5
+ module Karatekit
6
+
7
+ class << self
8
+ include Karatekit::Configurable
9
+
10
+ # API client based on configured options {Configurable}
11
+ #
12
+ # @return [Karatekit::Client] API wrapper
13
+ def client
14
+ return @client if defined?(@client) && @client.same_options?(options)
15
+ @client = Karatekit::Client.new(options)
16
+ end
17
+
18
+ private
19
+
20
+ def respond_to_missing?(method_name, include_private=false)
21
+ client.respond_to?(method_name, include_private)
22
+ end
23
+
24
+ def method_missing(method_name, *args, &block)
25
+ if client.respond_to?(method_name)
26
+ return client.send(method_name, *args, &block)
27
+ end
28
+
29
+ super
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ Karatekit.setup
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: karatekit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Puglisi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sawyer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.3
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.3
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.16'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.16'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.12'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.12'
89
+ description: Ruby toolkit for the kampfsport.center API
90
+ email:
91
+ - daniel@codegestalt.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
+ - CODE_OF_CONDUCT.md
99
+ - Gemfile
100
+ - Gemfile.lock
101
+ - MIT-LICENSE.md
102
+ - README.md
103
+ - Rakefile
104
+ - bin/console
105
+ - bin/setup
106
+ - karatekit.gemspec
107
+ - lib/karatekit.rb
108
+ - lib/karatekit/arguments.rb
109
+ - lib/karatekit/authentication.rb
110
+ - lib/karatekit/client.rb
111
+ - lib/karatekit/client/event_details.rb
112
+ - lib/karatekit/client/event_parts.rb
113
+ - lib/karatekit/client/events.rb
114
+ - lib/karatekit/client/instructor_details.rb
115
+ - lib/karatekit/client/instructor_group_members.rb
116
+ - lib/karatekit/client/instructor_groups.rb
117
+ - lib/karatekit/client/instructors.rb
118
+ - lib/karatekit/client/locations.rb
119
+ - lib/karatekit/client/posts.rb
120
+ - lib/karatekit/client/products.rb
121
+ - lib/karatekit/client/rate_limit.rb
122
+ - lib/karatekit/client/sessions.rb
123
+ - lib/karatekit/configurable.rb
124
+ - lib/karatekit/connection.rb
125
+ - lib/karatekit/default.rb
126
+ - lib/karatekit/error.rb
127
+ - lib/karatekit/rate_limit.rb
128
+ - lib/karatekit/response/raise_error.rb
129
+ - lib/karatekit/version.rb
130
+ - lib/karatekit/warnable.rb
131
+ homepage: https://kampfsport.center
132
+ licenses: []
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.5.2.3
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Ruby toolkit for the kampfsport.center API
154
+ test_files: []