blog_api 1.0.0 → 2.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: 75c62671b87032041e80a9cc95e7a73394380bf9
4
- data.tar.gz: 76f0cf3318da7e7102dccdb71572d9b2bedbdc1c
3
+ metadata.gz: 8315e2d57170310949897e02c466ab9513b42f5d
4
+ data.tar.gz: e0884d74607f0bf66ae9043b7ec8ff2bf4446e1a
5
5
  SHA512:
6
- metadata.gz: cc63040953c82dd074dfab9e131d7df0146692d1eb8cdabc0e082762803a4c1f1ff1c6d6a6106f0ab6eca8bf51dbad4f5fb1fc3837042a3a26f19ec9253e4ffc
7
- data.tar.gz: '029cca92ee1f62234f2539cd314ed67322635693149c5f89481747b30a2664984d40aed331610bd69b33be1d3aa26e55eb5371a61162921156f86080f3a6e333'
6
+ metadata.gz: d1e44d8d4205710459f47636ca5cc282af4cbb531bea7842a0d9396fc23b07423ecc627426b3c0c380580bca736c74637b90d52524adbec0a913e65a0efd64e1
7
+ data.tar.gz: f49da7459d638bb1f8f7bd8327446bd5707fb254fe8f793d38d7b0390fe79b21de6546fc303cad04d230e35d6ec563669815b21871effdaae77ccb2d5c4cba50
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blog_api (1.0.0)
4
+ blog_api (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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::Category.all
31
+ BlogApi.categories
32
32
  # Get all the tags.
33
- BlogApi::Tag.all
33
+ BlogApi.tags
34
34
  # Get all the posts.
35
- BlogApi::Post.all
35
+ BlogApi.posts
36
36
  # Get a specific post.
37
- BlogApi::Post.post(post_id)
37
+ BlogApi.post(post_id)
38
38
  # Get all the featured posts.
39
- BlogApi::Post.featured
39
+ BlogApi.featured_posts
40
40
  ```
41
41
 
42
42
  ## Development
data/examples/requests.rb CHANGED
@@ -1 +1,7 @@
1
1
  require_relative '../lib/blog_api'
2
+
3
+ p BlogApi.categories
4
+ p BlogApi.posts
5
+ p BlogApi.post(2)
6
+ p BlogApi.featured_posts
7
+ p BlogApi.tags
data/lib/blog_api.rb CHANGED
@@ -1,5 +1,36 @@
1
1
  require './lib/blog_api/version'
2
- require './lib/blog_api/request'
3
- require './lib/blog_api/post'
4
- require './lib/blog_api/category'
5
- require './lib/blog_api/tag'
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
@@ -0,0 +1,8 @@
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
@@ -1,3 +1,3 @@
1
1
  module BlogApi
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
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: 1.0.0
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-01 00:00:00.000000000 Z
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/category.rb
77
- - lib/blog_api/post.rb
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:
@@ -1,7 +0,0 @@
1
- module BlogApi
2
- class Category
3
- def self.all
4
- BlogApi::Request.get('/categories')
5
- end
6
- end
7
- end
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
@@ -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
data/lib/blog_api/tag.rb DELETED
@@ -1,7 +0,0 @@
1
- module BlogApi
2
- class Tag
3
- def self.all
4
- BlogApi::Request.get('tags')
5
- end
6
- end
7
- end