kipalog_api 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0a3d7ceef2f3fe19bf244959b03cb1d61eb3735
4
+ data.tar.gz: 49cddc4f203bafebcba888ea84fc045c14a9bc4e
5
+ SHA512:
6
+ metadata.gz: 8dc27f8b4ffcb70f891a0068f5bae265af2fba5ecaad0df64e3179cc820090dcfcf08e2ace6664b95f5d6be048d2ee4ba76253c90781210fecde44842ba5ceb6
7
+ data.tar.gz: fbb84eef39fa27c59247f2d0be6a51c0325f4b7200a2c976cb832a44d0c92956153f7b459e106a6594e9943c4afdc776723c5dc3a60d85c0e4af96fdbb195484
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kipalog_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kipalog_api"
8
+ spec.version = KipalogAPI::VERSION
9
+ spec.authors = ["Mai An"]
10
+ spec.email = ["maian27396@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby Wrapper for Kipalog API}
13
+ spec.description = %q{Ruby wrapper for Kipalog API}
14
+ spec.homepage = "https://github.com/huynhquancam/kipalog"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = ["kipalog_api.gemspec", "lib/kipalog_api.rb", "lib/kipalog_api/api_client.rb", "lib/kipalog_api/configuration.rb", "lib/kipalog_api/post.rb", "lib/kipalog_api/response.rb", "lib/kipalog_api/version.rb"]
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "httparty", "~> 0.14"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.12"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+ spec.add_development_dependency "webmock"
36
+ end
@@ -0,0 +1,21 @@
1
+ require "kipalog_api/version"
2
+
3
+ module KipalogAPI
4
+ class << self
5
+ def configure
6
+ yield(config)
7
+ end
8
+
9
+ def config
10
+ @config ||= Configuration.new
11
+ end
12
+ end
13
+
14
+ class RequestError < ::StandardError; end
15
+ end
16
+
17
+ require 'kipalog_api/configuration'
18
+ require 'kipalog_api/post'
19
+ require 'kipalog_api/response'
20
+ require 'kipalog_api/api_client'
21
+
@@ -0,0 +1,65 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module KipalogAPI
5
+ class APIClient
6
+ BASE_URI = 'https://kipalog.com/api/v1'.freeze
7
+ X_KIPALOG_TOKEN = 'X-Kipalog-Token'.freeze
8
+ ACCEPT_CHARSET = 'Accept-Charset'
9
+ DEFAULT_CHARSET = 'application/json'
10
+
11
+ def initialize(config = KipalogAPI.config)
12
+ @config = config
13
+ end
14
+
15
+ def get(path)
16
+ send_request(:get, path)
17
+ end
18
+
19
+ def post(path, request_body)
20
+ send_request(:post, path, request_body)
21
+ end
22
+
23
+ def send_request(method, path, body_hash = {})
24
+ _make_request(method, path, body_hash) do |result|
25
+ response = KipalogAPI::Response.new(
26
+ result.code,
27
+ result.headers,
28
+ result.parsed_response
29
+ )
30
+
31
+ if response.ok?
32
+ response
33
+ else
34
+ raise RequestError, response.body
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :config
42
+
43
+ def _make_request(method, path, body_hash)
44
+ yield(HTTParty.send(method, path, _request_options(body_hash)))
45
+ rescue HTTParty::Error => e
46
+ raise RequestError, e.message
47
+ end
48
+
49
+ def _request_options(body_hash)
50
+ {
51
+ base_uri: BASE_URI,
52
+ body: body_hash.to_json,
53
+ headers: _headers
54
+ }
55
+ end
56
+
57
+ def _headers
58
+ {
59
+ X_KIPALOG_TOKEN => config.token,
60
+ ACCEPT_CHARSET => DEFAULT_CHARSET
61
+ }
62
+ end
63
+ end
64
+ end
65
+
@@ -0,0 +1,13 @@
1
+ module KipalogAPI
2
+ class Configuration
3
+
4
+ KIPALOG_API_KEY = 'KIPALOG_API_KEY'.freeze
5
+
6
+ attr_accessor :api_key
7
+ alias :token :api_key
8
+
9
+ def initialize(api_key = '')
10
+ @api_key = api_key
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module KipalogAPI
2
+ class Post
3
+ class << self
4
+ def client
5
+ KipalogAPI::APIClient.new
6
+ end
7
+
8
+ def preview(content)
9
+ client.post('/post/preview', content: content)
10
+ end
11
+
12
+ def create(data)
13
+ client.post('/post', data)
14
+ end
15
+
16
+ def hot
17
+ client.get('/post/hot')
18
+ end
19
+
20
+ def newest
21
+ client.get('/post/newest')
22
+ end
23
+
24
+ def bytag(tag_name)
25
+ client.post('/post/bytag', { tag_name: tag_name })
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ module KipalogAPI
2
+ class Response
3
+ attr_reader :status_code, :headers, :body
4
+
5
+ def initialize(status_code, headers, body)
6
+ @status_code = status_code
7
+ @headers = headers
8
+ @body = body
9
+ end
10
+
11
+ def ok?
12
+ status_code == 200
13
+ end
14
+
15
+ def error?
16
+ !ok?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module KipalogAPI
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kipalog_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Mai An
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby wrapper for Kipalog API
84
+ email:
85
+ - maian27396@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - kipalog_api.gemspec
91
+ - lib/kipalog_api.rb
92
+ - lib/kipalog_api/api_client.rb
93
+ - lib/kipalog_api/configuration.rb
94
+ - lib/kipalog_api/post.rb
95
+ - lib/kipalog_api/response.rb
96
+ - lib/kipalog_api/version.rb
97
+ homepage: https://github.com/huynhquancam/kipalog
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ allowed_push_host: https://rubygems.org
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.6.11
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Ruby Wrapper for Kipalog API
122
+ test_files: []