okay 5.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/examples/github-graphql-example.rb +10 -0
- data/lib/okay/http.rb +35 -0
- data/lib/okay/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89ee2cbda6f5519c795f0f63330492e35f67b31b3e68fbda68e3dda6358c5f76
|
4
|
+
data.tar.gz: 1556c602c47c035ef3fd20a65ca20a2e92f04c15eb4bcbe65cfe297ecf7f7880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c39d51d59a0ce40101dc6af8d54216063ba4656457ed1edf4d05e9791b57560ee4f8e547a90a09d2cca5a88bb073021acbbe650ab951c3f080dd084cd5106055
|
7
|
+
data.tar.gz: 92f4c7175e6e1d18e5edda82a42b23dbabf6a5be2c05e45ab14cb48874df7eff2eab6048b4896c679c02c4fdc75e8336490e5a2a6e1369fb9e8d26efc6a95cf2
|
data/README.md
CHANGED
@@ -80,9 +80,9 @@ query = GraphQL.query {
|
|
80
80
|
response = request.submit!(:github, {bearer_token: ENV["DEMO_GITHUB_TOKEN"]})
|
81
81
|
JSON.parse(response.body)
|
82
82
|
# =>
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
# {"data" =>
|
84
|
+
# {"viewer" =>
|
85
|
+
# {"login" => "duckinator"}}}
|
86
86
|
```
|
87
87
|
|
88
88
|
## Development
|
data/lib/okay/http.rb
CHANGED
@@ -5,6 +5,41 @@ require "cacert"
|
|
5
5
|
|
6
6
|
Cacert.set_in_env
|
7
7
|
|
8
|
+
module Net
|
9
|
+
class HTTPResponse
|
10
|
+
# Returns false if the server encountered an error, true otherwise.
|
11
|
+
def okay?
|
12
|
+
self.value
|
13
|
+
true
|
14
|
+
rescue Net::HTTPExceptions
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
# Raises an exception if the request failed. (A fatal equivalent of +okay?+)
|
19
|
+
def or_raise!
|
20
|
+
self.value
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
# Converts the result from JSON if +okay?+ returns true; otherwise returns
|
25
|
+
# nil.
|
26
|
+
#
|
27
|
+
# Can be combined with +or_raise!+ to get a JSON result or raise an
|
28
|
+
# exception:
|
29
|
+
#
|
30
|
+
# Okay::HTTP.get("https://example.org/blah.json").or_raise!.from_json
|
31
|
+
def from_json
|
32
|
+
require "json"
|
33
|
+
|
34
|
+
if okay?
|
35
|
+
JSON.parse(body)
|
36
|
+
else
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
8
43
|
module Okay
|
9
44
|
module HTTP
|
10
45
|
RedirectLimitError = Class.new(StandardError)
|
data/lib/okay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: okay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ellen Marie Dash
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openssl-better_defaults
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- Rakefile
|
113
113
|
- bin/console
|
114
114
|
- bin/setup
|
115
|
+
- examples/github-graphql-example.rb
|
115
116
|
- lib/okay.rb
|
116
117
|
- lib/okay/graphql.rb
|
117
118
|
- lib/okay/http.rb
|