blog_api 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -15
- data/README.md +11 -10
- data/examples/requests.rb +11 -5
- data/lib/blog_api.rb +0 -31
- data/lib/blog_api/client.rb +24 -10
- data/lib/blog_api/response.rb +20 -0
- data/lib/blog_api/version.rb +1 -1
- metadata +3 -3
- data/lib/blog_api/configuration.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed5a8b528474e70994d72667b1fcc306a12254e
|
4
|
+
data.tar.gz: 67991ed8c9b9b02bf4b9eaecfcd0f2eeb2b9cc60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26537c8caf4c959344ea7f31cf0b641063ee334f4369a30a2ebec2e2781292df73209c560d53abebbbfca8827160c00e0c91e1c10116d55cd0f4a8add66dd454
|
7
|
+
data.tar.gz: 1aea1ee084b4e8c0d490dc5b62aff8b0bec2763548198c831ff5a404b893fbaaae9373a15e8e78ba684f0df33e60a5506c8fea813fe4a807cc97a24f0c68a07f
|
data/Gemfile.lock
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
blog_api (
|
4
|
+
blog_api (3.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.3)
|
10
|
-
httparty (0.
|
10
|
+
httparty (0.18.0)
|
11
11
|
mime-types (~> 3.0)
|
12
12
|
multi_xml (>= 0.5.2)
|
13
|
-
mime-types (3.
|
13
|
+
mime-types (3.3.1)
|
14
14
|
mime-types-data (~> 3.2015)
|
15
|
-
mime-types-data (3.2019.
|
15
|
+
mime-types-data (3.2019.1009)
|
16
16
|
multi_xml (0.6.0)
|
17
17
|
rake (10.5.0)
|
18
|
-
rspec (3.
|
19
|
-
rspec-core (~> 3.
|
20
|
-
rspec-expectations (~> 3.
|
21
|
-
rspec-mocks (~> 3.
|
22
|
-
rspec-core (3.
|
23
|
-
rspec-support (~> 3.
|
24
|
-
rspec-expectations (3.
|
18
|
+
rspec (3.9.0)
|
19
|
+
rspec-core (~> 3.9.0)
|
20
|
+
rspec-expectations (~> 3.9.0)
|
21
|
+
rspec-mocks (~> 3.9.0)
|
22
|
+
rspec-core (3.9.1)
|
23
|
+
rspec-support (~> 3.9.1)
|
24
|
+
rspec-expectations (3.9.1)
|
25
25
|
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.
|
27
|
-
rspec-mocks (3.
|
26
|
+
rspec-support (~> 3.9.0)
|
27
|
+
rspec-mocks (3.9.1)
|
28
28
|
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
-
rspec-support (~> 3.
|
30
|
-
rspec-support (3.
|
29
|
+
rspec-support (~> 3.9.0)
|
30
|
+
rspec-support (3.9.2)
|
31
31
|
|
32
32
|
PLATFORMS
|
33
33
|
ruby
|
data/README.md
CHANGED
@@ -27,16 +27,17 @@ $ gem install blog_api
|
|
27
27
|
The examples are listed below.
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
client = BlogApi::Client.new
|
31
|
+
# Get all categories
|
32
|
+
client.categories
|
33
|
+
# Get all posts
|
34
|
+
client.posts
|
35
|
+
# Get a specific post
|
36
|
+
client.post(2)
|
37
|
+
# Get all the featured_posts
|
38
|
+
client.featured_posts
|
39
|
+
# Get all tags
|
40
|
+
client.tags
|
40
41
|
```
|
41
42
|
|
42
43
|
## Development
|
data/examples/requests.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
require_relative '../lib/blog_api'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
client = BlogApi::Client.new
|
4
|
+
# Get all categories
|
5
|
+
client.categories
|
6
|
+
# Get all posts
|
7
|
+
client.posts
|
8
|
+
# Get a specific post
|
9
|
+
client.post(2)
|
10
|
+
# Get all the featured_posts
|
11
|
+
client.featured_posts
|
12
|
+
# Get all tags
|
13
|
+
client.tags
|
data/lib/blog_api.rb
CHANGED
@@ -1,36 +1,5 @@
|
|
1
1
|
require_relative 'blog_api/version'
|
2
2
|
require_relative 'blog_api/client'
|
3
|
-
require_relative 'blog_api/configuration'
|
4
3
|
|
5
4
|
module BlogApi
|
6
|
-
attr_accessor :configuration
|
7
|
-
class << self
|
8
|
-
def configuration
|
9
|
-
@configuration = BlogApi::Configuration.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def client
|
13
|
-
BlogApi::Client.new(configuration)
|
14
|
-
end
|
15
|
-
|
16
|
-
def categories
|
17
|
-
client.get('categories')
|
18
|
-
end
|
19
|
-
|
20
|
-
def posts
|
21
|
-
client.get('posts')
|
22
|
-
end
|
23
|
-
|
24
|
-
def post(post_id)
|
25
|
-
client.get("posts/#{post_id}")
|
26
|
-
end
|
27
|
-
|
28
|
-
def featured_posts
|
29
|
-
client.get("featured_posts")
|
30
|
-
end
|
31
|
-
|
32
|
-
def tags
|
33
|
-
client.get("tags")
|
34
|
-
end
|
35
|
-
end
|
36
5
|
end
|
data/lib/blog_api/client.rb
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
require 'httparty'
|
2
|
-
|
3
|
-
require_relative './configuration'
|
2
|
+
require_relative './response'
|
4
3
|
|
5
4
|
module BlogApi
|
6
5
|
class Client
|
7
6
|
class RequestError < StandardError; end
|
8
|
-
|
7
|
+
DEFAULT_URL = 'https://k-blog0130.herokuapp.com/api/v2/'
|
8
|
+
attr_reader :base_url
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(base_url = DEFAULT_URL)
|
11
|
+
@base_url = base_url
|
12
12
|
end
|
13
13
|
|
14
14
|
def get(path, options: { format: :plain })
|
15
|
-
url = "#{
|
15
|
+
url = "#{base_url}/#{path}"
|
16
16
|
result = HTTParty.get(url, options)
|
17
17
|
|
18
18
|
raise RequestError unless result.response.code == '200'
|
19
19
|
|
20
|
-
|
20
|
+
BlogApi::Response.new(result)
|
21
|
+
end
|
22
|
+
|
23
|
+
def categories
|
24
|
+
get('categories').parsed_body
|
25
|
+
end
|
26
|
+
|
27
|
+
def posts
|
28
|
+
get('posts').parsed_body
|
21
29
|
end
|
22
30
|
|
23
|
-
|
31
|
+
def post(post_id)
|
32
|
+
get("posts/#{post_id}").parsed_body
|
33
|
+
end
|
34
|
+
|
35
|
+
def featured_posts
|
36
|
+
get("featured_posts").parsed_body
|
37
|
+
end
|
24
38
|
|
25
|
-
def
|
26
|
-
|
39
|
+
def tags
|
40
|
+
get("tags").parsed_body
|
27
41
|
end
|
28
42
|
end
|
29
43
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module BlogApi
|
4
|
+
class Response
|
5
|
+
def initialize(result)
|
6
|
+
@body = result.body
|
7
|
+
@headers = result.headers
|
8
|
+
@status = result.code
|
9
|
+
end
|
10
|
+
|
11
|
+
def parsed_body
|
12
|
+
json_parse(@body)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def json_parse(body, options: { symbolize_names: true })
|
17
|
+
JSON.parse(body, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/blog_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blog_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katsuki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,7 +74,7 @@ files:
|
|
74
74
|
- examples/requests.rb
|
75
75
|
- lib/blog_api.rb
|
76
76
|
- lib/blog_api/client.rb
|
77
|
-
- lib/blog_api/
|
77
|
+
- lib/blog_api/response.rb
|
78
78
|
- lib/blog_api/version.rb
|
79
79
|
homepage: https://github.com/K-Sato1995/blog_api
|
80
80
|
licenses:
|