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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5954167c96379ab1ee2a94068253b417f17bdea70a4d9b700b8e94e8e59c5495
4
- data.tar.gz: fad91f6ef89734072991b0985763b98a0c6195d7b0176d76ee3d401dbca645ae
3
+ metadata.gz: 89ee2cbda6f5519c795f0f63330492e35f67b31b3e68fbda68e3dda6358c5f76
4
+ data.tar.gz: 1556c602c47c035ef3fd20a65ca20a2e92f04c15eb4bcbe65cfe297ecf7f7880
5
5
  SHA512:
6
- metadata.gz: 96337777a6f774ff282af8f883b11411977b14ee43e277d1fb239dfe85a2ce805451ffcfdcc6f65608d7e3ac552bf82bdbce6138ed0bd88278901513f6ddb805
7
- data.tar.gz: a4cb525e1ab90e43d56a40e52641ef5143cc0a8e14554f47398b8b9d1bc39c80d4218683b38ef699cb13daed58835be83b64d7bebc68ab3213c56fe89bb63c2f
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
- {"data" =>
84
- {"viewer" =>
85
- {"login" => "duckinator"}}}
83
+ # {"data" =>
84
+ # {"viewer" =>
85
+ # {"login" => "duckinator"}}}
86
86
  ```
87
87
 
88
88
  ## Development
@@ -0,0 +1,10 @@
1
+ require "okay/graphql"
2
+
3
+ query = Okay::GraphQL.query {
4
+ viewer {
5
+ login
6
+ }
7
+ }
8
+
9
+ results = query.submit!(:github, {bearer_token: ENV['DEMO_GITHUB_TOKEN']}).or_raise!
10
+ puts results.from_json
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
@@ -1,3 +1,3 @@
1
1
  module Okay
2
- VERSION = "5.0.0"
2
+ VERSION = "6.0.0"
3
3
  end
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: 5.0.0
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: 2017-12-28 00:00:00.000000000 Z
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