cwsrb 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/bin/setup.bat +1 -0
- data/cwsrb.gemspec +30 -0
- data/lib/cwsrb.rb +7 -0
- data/lib/cwsrb/api.rb +36 -0
- data/lib/cwsrb/errors.rb +4 -0
- data/lib/cwsrb/helpers.rb +16 -0
- data/lib/cwsrb/version.rb +3 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a9819ae04560d78506287cd52a93a95c4309a20
|
4
|
+
data.tar.gz: fceb3bbf0edcf501d2ccff0540c962895d86d411
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f91cbacc3f81efa121e75ea643edd591fdd339ba73720ec8664d07384134c94cc00f9e9155ff944682b5ad1d13a5c7e62583518bac1fd20d8526b2281abb1ac
|
7
|
+
data.tar.gz: 852b4c8b3b989a134e55b97ab31f962135afcfa9ceb7cc7bc5aa3ab2cea816ec067a2763e0a594470caad5e550d27d7c37e9273323a2ebb7b5ba6e31e60d96b1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Unleashy
|
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,29 @@
|
|
1
|
+
# Cwsrb
|
2
|
+
|
3
|
+
Cwsrb is a simple API wrapper for [ConWorkShop](http://conworkshop.com).
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
* Ruby 2.1+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Check the [Development section](https://github.com/unleashy/cwsrb#development). I'll probably put this in [rubygems.org](https://rubygems.org) later.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
... TODO ...
|
16
|
+
|
17
|
+
## Development
|
18
|
+
|
19
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
20
|
+
|
21
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/unleashy/cwsrb. Don't forget to use rubocop!
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/bin/setup.bat
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bundle install
|
data/cwsrb.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cwsrb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'cwsrb'
|
8
|
+
spec.version = Cwsrb::VERSION
|
9
|
+
spec.authors = ['Unleashy']
|
10
|
+
spec.email = ['']
|
11
|
+
|
12
|
+
spec.summary = "Access Conworkshop's API with Ruby."
|
13
|
+
spec.description = "A simple wrapper for ConWorkShop's (http://conworkshop.com) API in Ruby."
|
14
|
+
spec.homepage = 'https://github.com/unleashy/cwsrb'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'httparty'
|
23
|
+
|
24
|
+
spec.required_ruby_version = '>= 2.1.0'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.40.0'
|
30
|
+
end
|
data/lib/cwsrb.rb
ADDED
data/lib/cwsrb/api.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'cwsrb/errors'
|
3
|
+
require 'cwsrb/helpers'
|
4
|
+
|
5
|
+
module Cwsrb
|
6
|
+
class API
|
7
|
+
include HTTParty
|
8
|
+
base_uri 'http://conworkshop.com'
|
9
|
+
|
10
|
+
def initialize(user_agent)
|
11
|
+
self.class.headers 'User-Agent' =>
|
12
|
+
"#{user_agent} CWSrb/#{Cwsrb::VERSION} (#{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL})"
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_karma(val)
|
16
|
+
# Determine if val is an ID or username.
|
17
|
+
usr = Cwsrb::Helpers.resolve(val)
|
18
|
+
response = self.class.get("/api?f=USER_KARMA&USER=#{usr}")
|
19
|
+
|
20
|
+
# Check if any errors occurred
|
21
|
+
Cwsrb::Helpers.check_for_errors(response)
|
22
|
+
|
23
|
+
response['out']
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_user(val)
|
27
|
+
usr = Cwsrb::Helpers.resolve(val)
|
28
|
+
response = self.class.get("/api?f=USER&USER=#{usr}")
|
29
|
+
|
30
|
+
# Check if any errors occurred
|
31
|
+
Cwsrb::Helpers.check_for_errors(response)
|
32
|
+
|
33
|
+
response['out']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/cwsrb/errors.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Cwsrb
|
2
|
+
module Helpers
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def resolve(val)
|
6
|
+
# Determine if val is an ID or username.
|
7
|
+
# ID is a bunch of numbers that can or cannot be followed by an 'S'.
|
8
|
+
# Username... is not an ID.
|
9
|
+
(val =~ /\A(S?\d+)\z/) ? val : "@#{val}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def check_for_errors(response)
|
13
|
+
raise Cwsrb::APIError, response['err_msg'] if response['err_idx'] > 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cwsrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Unleashy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-11 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.40.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.40.0
|
83
|
+
description: A simple wrapper for ConWorkShop's (http://conworkshop.com) API in Ruby.
|
84
|
+
email:
|
85
|
+
- ''
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- bin/setup.bat
|
101
|
+
- cwsrb.gemspec
|
102
|
+
- lib/cwsrb.rb
|
103
|
+
- lib/cwsrb/api.rb
|
104
|
+
- lib/cwsrb/errors.rb
|
105
|
+
- lib/cwsrb/helpers.rb
|
106
|
+
- lib/cwsrb/version.rb
|
107
|
+
homepage: https://github.com/unleashy/cwsrb
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 2.1.0
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.5.1
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Access Conworkshop's API with Ruby.
|
131
|
+
test_files: []
|