blog_api 1.0.0 → 2.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 +1 -1
- data/README.md +5 -5
- data/examples/requests.rb +6 -0
- data/lib/blog_api.rb +35 -4
- data/lib/blog_api/client.rb +29 -0
- data/lib/blog_api/configuration.rb +8 -0
- data/lib/blog_api/version.rb +1 -1
- metadata +4 -6
- data/lib/blog_api/category.rb +0 -7
- data/lib/blog_api/post.rb +0 -17
- data/lib/blog_api/request.rb +0 -26
- data/lib/blog_api/tag.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8315e2d57170310949897e02c466ab9513b42f5d
|
4
|
+
data.tar.gz: e0884d74607f0bf66ae9043b7ec8ff2bf4446e1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1e44d8d4205710459f47636ca5cc282af4cbb531bea7842a0d9396fc23b07423ecc627426b3c0c380580bca736c74637b90d52524adbec0a913e65a0efd64e1
|
7
|
+
data.tar.gz: f49da7459d638bb1f8f7bd8327446bd5707fb254fe8f793d38d7b0390fe79b21de6546fc303cad04d230e35d6ec563669815b21871effdaae77ccb2d5c4cba50
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -28,15 +28,15 @@ The examples are listed below.
|
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
# Get all the categories.
|
31
|
-
BlogApi
|
31
|
+
BlogApi.categories
|
32
32
|
# Get all the tags.
|
33
|
-
BlogApi
|
33
|
+
BlogApi.tags
|
34
34
|
# Get all the posts.
|
35
|
-
BlogApi
|
35
|
+
BlogApi.posts
|
36
36
|
# Get a specific post.
|
37
|
-
BlogApi
|
37
|
+
BlogApi.post(post_id)
|
38
38
|
# Get all the featured posts.
|
39
|
-
BlogApi
|
39
|
+
BlogApi.featured_posts
|
40
40
|
```
|
41
41
|
|
42
42
|
## Development
|
data/examples/requests.rb
CHANGED
data/lib/blog_api.rb
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
require './lib/blog_api/version'
|
2
|
-
require './lib/blog_api/
|
3
|
-
require './lib/blog_api/
|
4
|
-
|
5
|
-
|
2
|
+
require './lib/blog_api/client'
|
3
|
+
require './lib/blog_api/configuration'
|
4
|
+
|
5
|
+
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
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require_relative './configuration'
|
4
|
+
|
5
|
+
module BlogApi
|
6
|
+
class Client
|
7
|
+
class RequestError < StandardError; end
|
8
|
+
attr_reader :configuration
|
9
|
+
|
10
|
+
def initialize(configuration)
|
11
|
+
@configuration = configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(path, options: { format: :plain })
|
15
|
+
url = "#{configuration.base_url}/#{path}"
|
16
|
+
result = HTTParty.get(url, options)
|
17
|
+
|
18
|
+
raise RequestError unless result.response.code == '200'
|
19
|
+
|
20
|
+
json_parse(result)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def json_parse(result, options: { symbolize_names: true })
|
26
|
+
JSON.parse(result, options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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: 2.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: 2019-09-
|
11
|
+
date: 2019-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,10 +73,8 @@ files:
|
|
73
73
|
- blog_api.gemspec
|
74
74
|
- examples/requests.rb
|
75
75
|
- lib/blog_api.rb
|
76
|
-
- lib/blog_api/
|
77
|
-
- lib/blog_api/
|
78
|
-
- lib/blog_api/request.rb
|
79
|
-
- lib/blog_api/tag.rb
|
76
|
+
- lib/blog_api/client.rb
|
77
|
+
- lib/blog_api/configuration.rb
|
80
78
|
- lib/blog_api/version.rb
|
81
79
|
homepage: https://github.com/K-Sato1995/blog_api
|
82
80
|
licenses:
|
data/lib/blog_api/category.rb
DELETED
data/lib/blog_api/post.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module BlogApi
|
2
|
-
class Post
|
3
|
-
class << self
|
4
|
-
def all
|
5
|
-
BlogApi::Request.get('posts')
|
6
|
-
end
|
7
|
-
|
8
|
-
def post(post_id)
|
9
|
-
BlogApi::Request.get("posts/#{post_id}")
|
10
|
-
end
|
11
|
-
|
12
|
-
def featured
|
13
|
-
BlogApi::Request.get('featured_posts')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/blog_api/request.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module BlogApi
|
2
|
-
class Request
|
3
|
-
class RequestError < StandardError; end
|
4
|
-
require 'httparty'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
BASE_URL = 'https://k-blog0130.herokuapp.com/api/v2/'.freeze
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def get(path, options: { format: :plain })
|
11
|
-
url = "#{BASE_URL}/#{path}"
|
12
|
-
result = HTTParty.get(url, options)
|
13
|
-
|
14
|
-
raise RequestError unless result.response.code == '200'
|
15
|
-
|
16
|
-
json_parse(result)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def json_parse(result, options: { symbolize_names: true })
|
22
|
-
JSON.parse(result, options)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|