cwsrb 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f5f7a7480e1233b3cc3043f175298be9e970bfd
4
- data.tar.gz: d04fc19a79bd91e0b54883eff1407998ea592b11
3
+ metadata.gz: 4246d4926b2154bc2831dcd3ba29358522c1e91c
4
+ data.tar.gz: db76f712ee09ee8efd4351c86a8873dff4f1fb44
5
5
  SHA512:
6
- metadata.gz: f74e5d1623a70bde7e8f200bd333a34fe2d079a3ced37542f80312621c1cda33f4c4ddc03640cabcbd5c2aa9005c29f690fdbe25e2eb2d2834aa45fdeb2fc012
7
- data.tar.gz: 73a7540d911305e901dc865d4e77ac43c2d09a6475368347c3dfd66c8fe0b4d94be30c5fdc6bd4c2b39f0b212fc138d5dfe914da80d6898eb68ab19f7b678bf9
6
+ metadata.gz: 1dfd4cd995f8729ea36f3378617379a6deb35a6a9d1f694641e98869e7814b08c5fe5f82b32ebc2685339d2b748a2e3bb5792a637c01d251c0a935d58ff320b5
7
+ data.tar.gz: fb66323f08d65b0deab1a1b056ef9e0a5078f3348103828aedb96c02ed4de7a1ebe22dbfae3e71ab3b8a1b9844fad402b46f309e7e9770474ee79eb5a89b365b
@@ -1,35 +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
-
17
- Metrics/LineLength:
18
- Enabled: false
19
-
20
- Metrics/MethodLength:
21
- Enabled: false
22
-
23
- Metrics/ParameterLists:
24
- Enabled: false
25
-
26
- Metrics/PerceivedComplexity:
27
- Enabled: false
28
-
29
- Style/Documentation:
30
- Exclude:
31
- - 'spec/**/*'
32
-
33
- AllCops:
34
- Exclude:
35
- - 'bin/**/*'
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
+
17
+ Metrics/LineLength:
18
+ Enabled: false
19
+
20
+ Metrics/MethodLength:
21
+ Enabled: false
22
+
23
+ Metrics/ParameterLists:
24
+ Enabled: false
25
+
26
+ Metrics/PerceivedComplexity:
27
+ Enabled: false
28
+
29
+ Style/Documentation:
30
+ Exclude:
31
+ - 'spec/**/*'
32
+
33
+ AllCops:
34
+ Exclude:
35
+ - 'bin/**/*'
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+ * Add new `Language` class and related subclasses `Type` and `Status` that are returned for calls to `API#get_lang`,
5
+ `API#get_lang_type` and `API#get_lang_status`, respectively
6
+ * Add new `API#api_version` to get the API version returned by CWS
7
+ * Since the API now merged the functions `USER` and `USER_KARMA`, it is reflected in CWSrb correctly now
8
+ * **TODO**: documentation for the classes above
9
+
3
10
  ## 0.3.0
4
11
  * Documented everything I could with YARD. yay! ([#2](https://github.com/unleashy/cwsrb/issues/2))
5
12
  * Added `User` class that is returned for calls to `API#get_user`. ([#3](https://github.com/unleashy/cwsrb/issues/3))
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![Gem](https://img.shields.io/gem/v/cwsrb.svg)](https://rubygems.org/gems/cwsrb)
2
2
  [![Build Status](https://travis-ci.org/unleashy/cwsrb.svg?branch=master)](https://travis-ci.org/unleashy/cwsrb)
3
+ [![Inline docs](http://inch-ci.org/github/unleashy/cwsrb.svg?branch=master)](http://inch-ci.org/github/unleashy/cwsrb)
3
4
 
4
5
  # CWSrb
5
6
 
@@ -1,7 +1,7 @@
1
1
  require 'cwsrb/version'
2
2
  require 'cwsrb/errors'
3
3
  require 'cwsrb/helpers'
4
- require 'cwsrb/user'
4
+ require 'cwsrb/data'
5
5
  require 'cwsrb/api'
6
6
 
7
7
  # This module is the main 'namespace' for CWSrb, and is extended in all other CWSrb files.
@@ -1,19 +1,19 @@
1
1
  require 'httparty'
2
2
  require 'cwsrb/errors'
3
3
  require 'cwsrb/helpers'
4
- require 'cwsrb/user'
4
+ require 'cwsrb/data'
5
5
 
6
6
  module Cwsrb
7
7
  # This is the main class from which you use CWSrb.
8
8
  # It includes `HTTParty` with a `base_uri` of "http://conworkshop.com".
9
9
  class API
10
10
  include HTTParty
11
- base_uri 'http://conworkshop.com'
11
+ base_uri 'conworkshop.com'
12
12
 
13
13
  # Initialize a new instance of the API object, with a mandatory custom User-Agent for HTTP requests.
14
14
  # This sets the User-Agent header for all subsequent requests, with your custom User-Agent and CWSrb's User-Agent.
15
15
  # @param user_agent [String] The User-Agent to use with HTTP requests. Please use a descriptive one.
16
- # @return [void] _dust_
16
+ # @return [API] a new instance of `API`
17
17
  def initialize(user_agent)
18
18
  self.class.headers 'User-Agent' =>
19
19
  "#{user_agent} CWSrb/#{Cwsrb::VERSION} (#{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL})"
@@ -27,7 +27,7 @@ module Cwsrb
27
27
  usr = Cwsrb::Helpers.resolve(val)
28
28
 
29
29
  # First general info
30
- response = self.class.get("/api?f=USER&USER=#{usr}")
30
+ response = self.class.get("/api/USER/#{usr}")
31
31
 
32
32
  # Check if any errors occurred
33
33
  Cwsrb::Helpers.check_for_errors(response)
@@ -38,19 +38,66 @@ module Cwsrb
38
38
  name: response['USER_NAME'],
39
39
  gender: response['USER_GENDER'],
40
40
  bio: response['USER_BIO'],
41
- country: response['USER_COUNTRY']
41
+ country: response['USER_COUNTRY'],
42
+ karma: response['KARMA']
42
43
  }
43
44
 
44
- # Now karma
45
- response = self.class.get("/api?f=USER_KARMA&USER=#{usr}")
45
+ Cwsrb::User.new(attribs)
46
+ end
47
+
48
+ def get_lang(val)
49
+ response = self.class.get("/api/LANG/#{val}")
46
50
 
47
- # Check if any errors occurred
48
51
  Cwsrb::Helpers.check_for_errors(response)
49
52
 
50
53
  response = response['out']
51
- attribs[:karma] = [response['KARMA_UP'], response['KARMA_DOWN']]
54
+ attribs = {
55
+ code: response['CODE'],
56
+ name: response['NAME'],
57
+ native_name: response['NATIVE_NAME'],
58
+ ipa: response['IPA'],
59
+ type: get_lang_type(response['TYPE']),
60
+ owners: response['OWNERS'],
61
+ overview: response['OVERVIEW'],
62
+ public: response['PUBLIC'],
63
+ status: get_lang_status(response['STATUS']),
64
+ registered: Time.at(response['REGISTERED']),
65
+ word_count: response['WORD_COUNT']
66
+ }
52
67
 
53
- Cwsrb::User.new(attribs)
68
+ Cwsrb::Language.new(attribs)
69
+ end
70
+
71
+ def get_lang_type(val)
72
+ response = self.class.get("/api/LANG/TYPE/#{val}")
73
+
74
+ Cwsrb::Helpers.check_for_errors(response)
75
+
76
+ response = response['out']
77
+ attribs = {
78
+ code: response['TYPE'].upcase,
79
+ desc: response['DESC']
80
+ }
81
+
82
+ Cwsrb::Language::Type.new(attribs)
83
+ end
84
+
85
+ def get_lang_status(val)
86
+ response = self.class.get("/api/LANG/STATUS/#{val}")
87
+
88
+ Cwsrb::Helpers.check_for_errors(response)
89
+
90
+ response = response['out']
91
+ attribs = {
92
+ code: response['STATUS'].upcase,
93
+ desc: response['DESC']
94
+ }
95
+
96
+ Cwsrb::Language::Status.new(attribs)
97
+ end
98
+
99
+ def api_version
100
+ self.class.get('/api')['api_ver']
54
101
  end
55
102
  end
56
103
  end
@@ -0,0 +1,110 @@
1
+ module Cwsrb
2
+ # The User class represents a member of ConWorkShop.
3
+ class User
4
+ # @return [String, Integer] The User's ID
5
+ attr_reader :id
6
+
7
+ # @return [String] The User's name
8
+ attr_reader :name
9
+
10
+ # @return [String] The User's gender, one of "Male", "Female", "Cyborg" or "Other"
11
+ attr_reader :gender
12
+
13
+ # @return [String] The User's bio, max 1000 characters
14
+ attr_reader :bio
15
+
16
+ # @return [String] The User's country
17
+ attr_reader :country
18
+
19
+ # @return [Array<(Integer, Integer)>] The User's karma counts; first one is upvotes and second one is downvotes
20
+ attr_reader :karma
21
+
22
+ # Initializes a new User instance with an options hash.
23
+ # @param id [String, Integer] The user's ID: a bunch of numbers that may or may not be prefixed with 'S'.
24
+ # @param name [String] The user's name. Defaults to `nil`.
25
+ # @param gender [String] The user's gender, one of "Male", "Female", "Cyborg" or "Other". Defaults to "Other".
26
+ # @param bio [String] The user's bio or about section. Defaults to an empty string.
27
+ # @param country [String] The user's country. Defaults to "Unknown".
28
+ # @param karma [Array<(Integer, Integer)>] The user's karma counts (first is upvotes, second is downvotes). Defaults to zero for both.
29
+ # @return [User] a new instance of `User`
30
+ def initialize(id: nil, name: nil, gender: 'Other', bio: '', country: 'Unknown', karma: [0, 0])
31
+ @id = id
32
+ @name = name
33
+ @gender = gender
34
+ @bio = bio
35
+ @country = country
36
+ @karma = karma
37
+ end
38
+
39
+ # @overload inspect
40
+ # @return [String] A more meaningful output than that of the default inspect method, with all of User's attributes.
41
+ def inspect
42
+ "<User id=#{@id} name=#{@name} gender=#{gender} bio=#{bio} country=#{country} karma=#{karma}>"
43
+ end
44
+ end
45
+
46
+ class Language
47
+ class Type
48
+ attr_reader :code
49
+ attr_reader :desc
50
+
51
+ def initialize(code: nil, desc: '')
52
+ @code = code
53
+ @desc = desc
54
+ end
55
+
56
+ def inspect
57
+ "<Language::Type code=#{@code} desc=#{@desc}>"
58
+ end
59
+ end
60
+
61
+ class Status
62
+ attr_reader :code
63
+ attr_reader :desc
64
+
65
+ def initialize(code: nil, desc: '')
66
+ @code = code
67
+ @desc = desc
68
+ end
69
+
70
+ def inspect
71
+ "<Language::Status code=#{@code} desc=#{@desc}>"
72
+ end
73
+ end
74
+
75
+ attr_reader :code
76
+ attr_reader :name
77
+ attr_reader :native_name
78
+ attr_reader :ipa
79
+ attr_reader :type
80
+ attr_reader :owners
81
+ attr_reader :overview
82
+ attr_reader :public
83
+ attr_reader :status
84
+ attr_reader :registered
85
+ attr_reader :word_count
86
+
87
+ def initialize(code: nil, name: nil, native_name: nil, ipa: nil, type: nil,
88
+ owners: [], overview: '', public: true, status: '',
89
+ registered: Time.now, word_count: 0)
90
+ @code = code
91
+ @name = name
92
+ @native_name = native_name
93
+ @ipa = ipa
94
+ @type = type
95
+ @owners = owners
96
+ @overview = overview
97
+ @public = public
98
+ @status = status
99
+ @registered = registered
100
+ @word_count = word_count
101
+ end
102
+
103
+ def inspect
104
+ "<Language code=#{@code} name=#{@name} native_name=#{@native_name} " \
105
+ "ipa=#{@ipa} type=#{@type} owners=#{@owners} overview=#{@overview} " \
106
+ "public=#{@public} status=#{@status} registered=#{@registered} " \
107
+ "word_count=#{@word_count}>"
108
+ end
109
+ end
110
+ end
@@ -1,12 +1,8 @@
1
1
  module Cwsrb
2
- # @!group Errors
3
-
4
2
  # @abstract This class subclasses `RuntimeError` and serves as a base
5
3
  # for all other CWSrb's error classes.
6
4
  Error = Class.new(RuntimeError)
7
5
 
8
- # Raised when a general APIError occurs.
6
+ # Raised when a general API error occurs.
9
7
  APIError = Class.new(Error)
10
-
11
- # @!endgroup
12
8
  end
@@ -17,7 +17,7 @@ module Cwsrb
17
17
  # Verifies if the response has any errors, and if so, raises a `APIError`.
18
18
  # @param response [Hash<String, String>] the response hash to check for errors
19
19
  # @raise [APIError] if any errors are detected in the response
20
- # @return [void] _dust_
20
+ # @return [void]
21
21
  def check_for_errors(response)
22
22
  raise Cwsrb::APIError, response['err_msg'] if response['err_idx'] > 0
23
23
  end
@@ -1,4 +1,4 @@
1
1
  module Cwsrb
2
2
  # The current version of CWSrb.
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.4.0'.freeze
4
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.3.0
4
+ version: 0.4.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-12 00:00:00.000000000 Z
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -103,9 +103,9 @@ files:
103
103
  - cwsrb.gemspec
104
104
  - lib/cwsrb.rb
105
105
  - lib/cwsrb/api.rb
106
+ - lib/cwsrb/data.rb
106
107
  - lib/cwsrb/errors.rb
107
108
  - lib/cwsrb/helpers.rb
108
- - lib/cwsrb/user.rb
109
109
  - lib/cwsrb/version.rb
110
110
  homepage: https://github.com/unleashy/cwsrb
111
111
  licenses:
@@ -1,51 +0,0 @@
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