blog_api 2.0.1 → 3.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
  SHA1:
3
- metadata.gz: a15d6f6be6455ad71850274a7f97fe3ec62c9dd3
4
- data.tar.gz: 3c37ad51527945784378a1e5484a97c4bd38c759
3
+ metadata.gz: 4ed5a8b528474e70994d72667b1fcc306a12254e
4
+ data.tar.gz: 67991ed8c9b9b02bf4b9eaecfcd0f2eeb2b9cc60
5
5
  SHA512:
6
- metadata.gz: 5e08379b2668383747dedef7cd8d24f3f6a1be7745b2b0c0b121309eb6389a55e910181a4bfceaff1a84dce63d8147a86c6a41e98a836c4012589b0f44b72032
7
- data.tar.gz: 2b90def025ff2fc366481b51435f97522fa18d5f309a220217d00ed39d6fca8c471c098ed7008bceca1ecaa132649419f563fd8e8c22d10e5f273cf430d2df05
6
+ metadata.gz: 26537c8caf4c959344ea7f31cf0b641063ee334f4369a30a2ebec2e2781292df73209c560d53abebbbfca8827160c00e0c91e1c10116d55cd0f4a8add66dd454
7
+ data.tar.gz: 1aea1ee084b4e8c0d490dc5b62aff8b0bec2763548198c831ff5a404b893fbaaae9373a15e8e78ba684f0df33e60a5506c8fea813fe4a807cc97a24f0c68a07f
@@ -1,33 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blog_api (2.0.1)
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.17.0)
10
+ httparty (0.18.0)
11
11
  mime-types (~> 3.0)
12
12
  multi_xml (>= 0.5.2)
13
- mime-types (3.2.2)
13
+ mime-types (3.3.1)
14
14
  mime-types-data (~> 3.2015)
15
- mime-types-data (3.2019.0331)
15
+ mime-types-data (3.2019.1009)
16
16
  multi_xml (0.6.0)
17
17
  rake (10.5.0)
18
- rspec (3.8.0)
19
- rspec-core (~> 3.8.0)
20
- rspec-expectations (~> 3.8.0)
21
- rspec-mocks (~> 3.8.0)
22
- rspec-core (3.8.2)
23
- rspec-support (~> 3.8.0)
24
- rspec-expectations (3.8.4)
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.8.0)
27
- rspec-mocks (3.8.1)
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.8.0)
30
- rspec-support (3.8.2)
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
- # Get all the categories.
31
- BlogApi.categories
32
- # Get all the tags.
33
- BlogApi.tags
34
- # Get all the posts.
35
- BlogApi.posts
36
- # Get a specific post.
37
- BlogApi.post(post_id)
38
- # Get all the featured posts.
39
- BlogApi.featured_posts
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
@@ -1,7 +1,13 @@
1
1
  require_relative '../lib/blog_api'
2
2
 
3
- p BlogApi.categories
4
- p BlogApi.posts
5
- p BlogApi.post(2)
6
- p BlogApi.featured_posts
7
- p BlogApi.tags
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
@@ -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
@@ -1,29 +1,43 @@
1
1
  require 'httparty'
2
- require 'json'
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
- attr_reader :configuration
7
+ DEFAULT_URL = 'https://k-blog0130.herokuapp.com/api/v2/'
8
+ attr_reader :base_url
9
9
 
10
- def initialize(configuration)
11
- @configuration = configuration
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 = "#{configuration.base_url}/#{path}"
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
- json_parse(result)
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
- private
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 json_parse(result, options: { symbolize_names: true })
26
- JSON.parse(result, options)
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
@@ -1,3 +1,3 @@
1
1
  module BlogApi
2
- VERSION = "2.0.1"
2
+ VERSION = '3.0.0'.freeze
3
3
  end
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: 2.0.1
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-02-15 00:00:00.000000000 Z
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/configuration.rb
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:
@@ -1,8 +0,0 @@
1
- module BlogApi
2
- class Configuration
3
- attr_reader :base_url
4
- def initialize
5
- @base_url = 'https://k-blog0130.herokuapp.com/api/v2/'
6
- end
7
- end
8
- end