kipalog 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1aa02774e9f553e891a9aec7f5af63e9e2b8b1fb
4
+ data.tar.gz: 55a7d64d55f63b04928e9e9dffa580c8d104941d
5
+ SHA512:
6
+ metadata.gz: 4548762600e4ba326dd9a475b15eaa4410a63ff98280babba2661f7c33f7372425b53525061812bd445cbd10e5d6b8dc1e42da6f1b6080301553bb97dd0f2db6
7
+ data.tar.gz: 6313fad29387e1754a465b9c823840e1f0ab1bf9751d5404734d8e520198e20745b614d39fea4738d4c1179cd54b5d52ebefd5c0aa407f8038d085236f9ab396
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at huynhquancam@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kipalog.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Cam Huynh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # Kipalog
2
+
3
+ Ruby wrapper for Kipalog API
4
+
5
+ Original documentation see at: [https://github.com/Kipalog/Kipalog-API-Doc](https://github.com/Kipalog/Kipalog-API-Doc)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kipalog'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ $ bundle install
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### IMPORTANT: Configure your API token
24
+
25
+ ```ruby
26
+ Kipalog.configure do |config|
27
+ config.api_key = 'key-obtained-from-kipalog'
28
+ end
29
+ ```
30
+
31
+ If you're using *Rails*, you might want to consider putting it in `config/initializers/kipalog.rb`
32
+
33
+ ### `Kipalog::Post.preview`
34
+
35
+ ```ruby
36
+ markdown = %{
37
+ ### FOO
38
+ * Item A
39
+ * Item B
40
+ * Item C
41
+ }
42
+ Kipalog::Post.preview(markdown)
43
+ ```
44
+
45
+ ### `Kipalog::Post.create`
46
+
47
+
48
+ ```ruby
49
+ markdown = %{
50
+ ### FOO
51
+ * Item A
52
+ * Item B
53
+ * Item C
54
+ }
55
+
56
+ data = {
57
+ title: 'Hello World',
58
+ content: markdown,
59
+ tag: 'foo,bar',
60
+ status: 'published' # or "draft"
61
+ }
62
+ Kipalog::Post.create(data)
63
+ ```
64
+
65
+ ### `Kipalog::Post.newest`
66
+
67
+ Get all latest posts on Kipalog.com
68
+
69
+ ```ruby
70
+ Kipalog::Post.newest
71
+ ```
72
+
73
+ ### `Kipalog::Post.hot`
74
+
75
+ Get all the latest posts on Kipalog.com
76
+
77
+ ```ruby
78
+ Kipalog::Post.hot
79
+ ```
80
+
81
+ ### `Kipalog::Post.bytag`
82
+
83
+ Fetch all posts by a specific tag name
84
+
85
+ ```ruby
86
+ Kipalog::Post.bytag('ruby')
87
+ ```
88
+
89
+ ## Development
90
+
91
+ 1. Fork this repository.
92
+ 2. Add your feature as well as your test (in MiniTest).
93
+ 3. Send us a pull request.
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/huynhquancam/kipalog. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
102
+
103
+ The MIT License (MIT)
104
+
105
+ Copyright (c) 2016 Cam Huynh
106
+
107
+ Permission is hereby granted, free of charge, to any person obtaining a copy
108
+ of this software and associated documentation files (the "Software"), to deal
109
+ in the Software without restriction, including without limitation the rights
110
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
111
+ copies of the Software, and to permit persons to whom the Software is
112
+ furnished to do so, subject to the following conditions:
113
+
114
+ The above copyright notice and this permission notice shall be included in
115
+ all copies or substantial portions of the Software.
116
+
117
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
118
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
119
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
120
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
121
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
122
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
123
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/kipalog.gemspec ADDED
@@ -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/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kipalog"
8
+ spec.version = Kipalog::VERSION
9
+ spec.authors = ["Cam Huynh"]
10
+ spec.email = ["huynhquancam@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 = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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", "~> 2.1"
36
+ end
data/lib/kipalog.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "kipalog/version"
2
+
3
+ module Kipalog
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/configuration'
18
+ require 'kipalog/post'
19
+ require 'kipalog/response'
20
+ require 'kipalog/api_client'
21
+
@@ -0,0 +1,65 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Kipalog
5
+ class APIClient
6
+ BASE_URI = '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 = Kipalog.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 = Kipalog::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 Kipalog
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 Kipalog
2
+ class Post
3
+ class << self
4
+ def client
5
+ Kipalog::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 Kipalog
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 Kipalog
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kipalog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cam Huynh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-04 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: '2.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
83
+ description: Ruby wrapper for Kipalog API
84
+ email:
85
+ - huynhquancam@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - kipalog.gemspec
98
+ - lib/kipalog.rb
99
+ - lib/kipalog/api_client.rb
100
+ - lib/kipalog/configuration.rb
101
+ - lib/kipalog/post.rb
102
+ - lib/kipalog/response.rb
103
+ - lib/kipalog/version.rb
104
+ homepage: https://github.com/huynhquancam/kipalog
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Ruby Wrapper for Kipalog API
129
+ test_files: []