cwsrb 0.2.0 → 0.3.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: 3a9819ae04560d78506287cd52a93a95c4309a20
4
- data.tar.gz: fceb3bbf0edcf501d2ccff0540c962895d86d411
3
+ metadata.gz: 3f5f7a7480e1233b3cc3043f175298be9e970bfd
4
+ data.tar.gz: d04fc19a79bd91e0b54883eff1407998ea592b11
5
5
  SHA512:
6
- metadata.gz: 0f91cbacc3f81efa121e75ea643edd591fdd339ba73720ec8664d07384134c94cc00f9e9155ff944682b5ad1d13a5c7e62583518bac1fd20d8526b2281abb1ac
7
- data.tar.gz: 852b4c8b3b989a134e55b97ab31f962135afcfa9ceb7cc7bc5aa3ab2cea816ec067a2763e0a594470caad5e550d27d7c37e9273323a2ebb7b5ba6e31e60d96b1
6
+ metadata.gz: f74e5d1623a70bde7e8f200bd333a34fe2d079a3ced37542f80312621c1cda33f4c4ddc03640cabcbd5c2aa9005c29f690fdbe25e2eb2d2834aa45fdeb2fc012
7
+ data.tar.gz: 73a7540d911305e901dc865d4e77ac43c2d09a6475368347c3dfd66c8fe0b4d94be30c5fdc6bd4c2b39f0b212fc138d5dfe914da80d6898eb68ab19f7b678bf9
data/.rubocop.yml CHANGED
@@ -1,11 +1,35 @@
1
+ # no metrics
2
+ Metrics/AbcSize:
3
+ Enabled: false
4
+
5
+ Metrics/BlockNesting:
6
+ Enabled: false
7
+
8
+ Metrics/ClassLength:
9
+ Enabled: false
10
+
11
+ Metrics/ModuleLength:
12
+ Enabled: false
13
+
14
+ Metrics/CyclomaticComplexity:
15
+ Enabled: false
16
+
1
17
  Metrics/LineLength:
2
- Max: 120
18
+ Enabled: false
19
+
20
+ Metrics/MethodLength:
21
+ Enabled: false
22
+
23
+ Metrics/ParameterLists:
24
+ Enabled: false
25
+
26
+ Metrics/PerceivedComplexity:
27
+ Enabled: false
3
28
 
4
- # TODO: documentation (I SWEAR I'LL DO IT SOMEDAY)
5
29
  Style/Documentation:
6
30
  Exclude:
7
31
  - 'spec/**/*'
8
- - 'test/**/*'
9
- - 'lib/cwsrb.rb'
10
- - 'lib/cwsrb/api.rb'
11
- - 'lib/cwsrb/helpers.rb'
32
+
33
+ AllCops:
34
+ Exclude:
35
+ - 'bin/**/*'
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+ * Documented everything I could with YARD. yay! ([#2](https://github.com/unleashy/cwsrb/issues/2))
5
+ * Added `User` class that is returned for calls to `API#get_user`. ([#3](https://github.com/unleashy/cwsrb/issues/3))
6
+ * `Helpers#resolve` would return an @-prefixed string if you gave it an `Integer`. Well, no more! ([#1](https://github.com/unleashy/cwsrb/issues/1))
7
+ * Merged `API#get_karma` into `API#get_user`
8
+ * Made it so the testing console already initialized an API object for you
9
+ * Disabled metrics for rubocop
10
+
11
+ ## 0.2.0
12
+ * First release on GitHub
13
+
14
+ ## 0.1.0
15
+ * First actual release
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- # Cwsrb
1
+ [![Gem](https://img.shields.io/gem/v/cwsrb.svg)](https://rubygems.org/gems/cwsrb)
2
+ [![Build Status](https://travis-ci.org/unleashy/cwsrb.svg?branch=master)](https://travis-ci.org/unleashy/cwsrb)
2
3
 
3
- Cwsrb is a simple API wrapper for [ConWorkShop](http://conworkshop.com).
4
+ # CWSrb
5
+
6
+ CWSrb is a simple API wrapper for [ConWorkShop](http://conworkshop.com).
4
7
 
5
8
  ## Dependencies
6
9
 
@@ -8,11 +11,24 @@ Cwsrb is a simple API wrapper for [ConWorkShop](http://conworkshop.com).
8
11
 
9
12
  ## Installation
10
13
 
11
- Check the [Development section](https://github.com/unleashy/cwsrb#development). I'll probably put this in [rubygems.org](https://rubygems.org) later.
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'cwsrb'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install cwsrb
12
27
 
13
28
  ## Usage
14
29
 
15
- ... TODO ...
30
+ TODO
31
+ (I swear I'll fill this out)
16
32
 
17
33
  ## Development
18
34
 
data/bin/console CHANGED
@@ -3,5 +3,9 @@
3
3
  require 'bundler/setup'
4
4
  require 'cwsrb'
5
5
 
6
+ # Set up API object
7
+ api = Cwsrb::API.new('CWSrb Testing Console')
8
+ puts 'The Cwsrb::API object was initialized to the `api` variable.'
9
+
6
10
  require 'irb'
7
11
  IRB.start
data/lib/cwsrb.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'cwsrb/version'
2
2
  require 'cwsrb/errors'
3
3
  require 'cwsrb/helpers'
4
+ require 'cwsrb/user'
4
5
  require 'cwsrb/api'
5
6
 
7
+ # This module is the main 'namespace' for CWSrb, and is extended in all other CWSrb files.
6
8
  module Cwsrb
7
9
  end
data/lib/cwsrb/api.rb CHANGED
@@ -1,36 +1,56 @@
1
1
  require 'httparty'
2
2
  require 'cwsrb/errors'
3
3
  require 'cwsrb/helpers'
4
+ require 'cwsrb/user'
4
5
 
5
6
  module Cwsrb
7
+ # This is the main class from which you use CWSrb.
8
+ # It includes `HTTParty` with a `base_uri` of "http://conworkshop.com".
6
9
  class API
7
10
  include HTTParty
8
11
  base_uri 'http://conworkshop.com'
9
12
 
13
+ # Initialize a new instance of the API object, with a mandatory custom User-Agent for HTTP requests.
14
+ # This sets the User-Agent header for all subsequent requests, with your custom User-Agent and CWSrb's User-Agent.
15
+ # @param user_agent [String] The User-Agent to use with HTTP requests. Please use a descriptive one.
16
+ # @return [void] _dust_
10
17
  def initialize(user_agent)
11
18
  self.class.headers 'User-Agent' =>
12
19
  "#{user_agent} CWSrb/#{Cwsrb::VERSION} (#{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL})"
13
20
  end
14
21
 
15
- def get_karma(val)
16
- # Determine if val is an ID or username.
22
+ # Gets a ConWorkShop's user's info plus karma counts.
23
+ # @param val [String, Integer] The user's name or ID.
24
+ # @return [User] The user queried for
25
+ # @raise [APIError] If any error ocurred while querying for that user
26
+ def get_user(val)
17
27
  usr = Cwsrb::Helpers.resolve(val)
18
- response = self.class.get("/api?f=USER_KARMA&USER=#{usr}")
28
+
29
+ # First general info
30
+ response = self.class.get("/api?f=USER&USER=#{usr}")
19
31
 
20
32
  # Check if any errors occurred
21
33
  Cwsrb::Helpers.check_for_errors(response)
22
34
 
23
- response['out']
24
- end
35
+ response = response['out']
36
+ attribs = {
37
+ id: response['USER_ID'],
38
+ name: response['USER_NAME'],
39
+ gender: response['USER_GENDER'],
40
+ bio: response['USER_BIO'],
41
+ country: response['USER_COUNTRY']
42
+ }
25
43
 
26
- def get_user(val)
27
- usr = Cwsrb::Helpers.resolve(val)
28
- response = self.class.get("/api?f=USER&USER=#{usr}")
44
+ # Now karma
45
+ response = self.class.get("/api?f=USER_KARMA&USER=#{usr}")
29
46
 
30
47
  # Check if any errors occurred
31
48
  Cwsrb::Helpers.check_for_errors(response)
32
49
 
33
- response['out']
50
+ response = response['out']
51
+ attribs[:karma] = [response['KARMA_UP'], response['KARMA_DOWN']]
52
+
53
+ Cwsrb::User.new(attribs)
34
54
  end
35
55
  end
36
56
  end
data/lib/cwsrb/errors.rb CHANGED
@@ -1,4 +1,12 @@
1
1
  module Cwsrb
2
+ # @!group Errors
3
+
4
+ # @abstract This class subclasses `RuntimeError` and serves as a base
5
+ # for all other CWSrb's error classes.
2
6
  Error = Class.new(RuntimeError)
7
+
8
+ # Raised when a general APIError occurs.
3
9
  APIError = Class.new(Error)
10
+
11
+ # @!endgroup
4
12
  end
data/lib/cwsrb/helpers.rb CHANGED
@@ -1,14 +1,23 @@
1
1
  module Cwsrb
2
+ # This module has a bunch of utility functions for use in other files.
3
+ # All methods are marked as `module_function` so you can do things like `Helpers.resolve`.
2
4
  module Helpers
3
5
  module_function
4
6
 
7
+ # Determine if val is an ID or username.
8
+ # ID is a bunch of numbers that can or cannot be followed by an 'S'.
9
+ # Username... is not an ID.
10
+ # @param val [String, Integer] The value to discriminate
11
+ # @return [String, Integer] Either an '@'-prefixed `val` if it's an username or val itself if it isn't
5
12
  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.
13
+ return val if val.is_a?(Integer)
9
14
  (val =~ /\A(S?\d+)\z/) ? val : "@#{val}"
10
15
  end
11
16
 
17
+ # Verifies if the response has any errors, and if so, raises a `APIError`.
18
+ # @param response [Hash<String, String>] the response hash to check for errors
19
+ # @raise [APIError] if any errors are detected in the response
20
+ # @return [void] _dust_
12
21
  def check_for_errors(response)
13
22
  raise Cwsrb::APIError, response['err_msg'] if response['err_idx'] > 0
14
23
  end
data/lib/cwsrb/user.rb ADDED
@@ -0,0 +1,51 @@
1
+ module Cwsrb
2
+ # The User class represents an member of ConWorkShop.
3
+ class User
4
+ # @!attribute [r] id
5
+ # @return [String, Integer] The User's ID
6
+ attr_reader :id
7
+
8
+ # @!attribute [r] name
9
+ # @return [String] The User's name
10
+ attr_reader :name
11
+
12
+ # @!attribute [r] gender
13
+ # @return [String] The User's gender, one of "Male", "Female", "Cyborg" or "Other"
14
+ attr_reader :gender
15
+
16
+ # @!attribute [r] bio
17
+ # @return [String] The User's bio, max 1000 characters
18
+ attr_reader :bio
19
+
20
+ # @!attribute [r] country
21
+ # @return [String] The User's country
22
+ attr_reader :country
23
+
24
+ # @!attribute [r] karma
25
+ # @return [Array<(Integer, Integer)>] The User's karma counts. First one is upvotes and second one is downvotes.
26
+ attr_reader :karma
27
+
28
+ # Initializes a new User instance with an options hash.
29
+ # @param id [String, Integer] The user's ID: a bunch of numbers that may or may not be prefixed with 'S'.
30
+ # @param name [String] The user's name. Defaults to `nil`.
31
+ # @param gender [String] The user's gender, one of "Male", "Female", "Cyborg" or "Other". Defaults to "Other".
32
+ # @param bio [String] The user's bio or about section. Defaults to an empty string.
33
+ # @param country [String] The user's country. Defaults to "Unknown".
34
+ # @param karma [Array<(Integer, Integer)>] The user's karma counts (first is upvotes, second is downvotes). Defaults to zero for both.
35
+ # @return [void] _dust_
36
+ def initialize(id: nil, name: nil, gender: 'Other', bio: '', country: 'Unknown', karma: [0, 0])
37
+ @id = id
38
+ @name = name
39
+ @gender = gender
40
+ @bio = bio
41
+ @country = country
42
+ @karma = karma
43
+ end
44
+
45
+ # @overload inspect
46
+ # @return [String] A more meaningful output than that of the default inspect method, with all of User's attributes.
47
+ def inspect
48
+ "<User id=#{@id} name=#{@name} gender=#{gender} bio=#{bio} country=#{country} karma=#{karma}>"
49
+ end
50
+ end
51
+ end
data/lib/cwsrb/version.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  module Cwsrb
2
- VERSION = '0.2.0'.freeze
2
+ # The current version of CWSrb.
3
+ VERSION = '0.3.0'.freeze
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cwsrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unleashy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-11 00:00:00.000000000 Z
11
+ date: 2016-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -91,6 +91,8 @@ files:
91
91
  - ".rspec"
92
92
  - ".rubocop.yml"
93
93
  - ".travis.yml"
94
+ - ".yardopts"
95
+ - CHANGELOG.md
94
96
  - Gemfile
95
97
  - LICENSE.txt
96
98
  - README.md
@@ -103,6 +105,7 @@ files:
103
105
  - lib/cwsrb/api.rb
104
106
  - lib/cwsrb/errors.rb
105
107
  - lib/cwsrb/helpers.rb
108
+ - lib/cwsrb/user.rb
106
109
  - lib/cwsrb/version.rb
107
110
  homepage: https://github.com/unleashy/cwsrb
108
111
  licenses: