cwsrb 0.4.1 → 0.5.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/cwsrb/api.rb +17 -2
- data/lib/cwsrb/data.rb +116 -15
- data/lib/cwsrb/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1047b109cebaf37d125e16e499710bf0a5c9d82f
|
|
4
|
+
data.tar.gz: 757b7e9773d1dc27571e9d8f03f2bde6e828ddd6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 572100c7be00822e56d341babb109afa315c58d19b0066cedd859c0856e6abc55d6750656b1a1886cbbe3ff12a899ccbad086559d01733edff65b84c21750987
|
|
7
|
+
data.tar.gz: 0b1906d32dd4fb5511965c7950c2ec38b381323b8746dc39bc636fda928d8e445c03dfd2c8abade8860ce9202d5b07a4e25351ced5e30a044f868d59c8b02050
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
* Added `#generate_link` to both `User` and `Language` that returns the corresponding CWS link to it.
|
|
5
|
+
* Added a `karma` attribute to `Language` which represents the karma values for the language.
|
|
6
|
+
* Updated documentation.
|
|
7
|
+
|
|
3
8
|
## 0.4.1
|
|
4
9
|
* Fixed an error with the URIs not being encoded
|
|
5
10
|
|
data/lib/cwsrb/api.rb
CHANGED
|
@@ -22,7 +22,7 @@ module Cwsrb
|
|
|
22
22
|
# Gets a ConWorkShop's user's info plus karma counts.
|
|
23
23
|
# @param val [String, Integer] The user's name or ID.
|
|
24
24
|
# @return [User] The user queried for
|
|
25
|
-
# @raise [APIError] If any error
|
|
25
|
+
# @raise [APIError] If any error occurred while querying for that user
|
|
26
26
|
def get_user(val)
|
|
27
27
|
usr = URI.encode(Cwsrb::Helpers.resolve(val))
|
|
28
28
|
|
|
@@ -45,6 +45,10 @@ module Cwsrb
|
|
|
45
45
|
Cwsrb::User.new(attribs)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# Gets a ConWorkShop's language's info plus karma counts.
|
|
49
|
+
# @param val [String] The language's three-character code.
|
|
50
|
+
# @return [Language] The language queried for.
|
|
51
|
+
# @raise [APIError] If any error occurred while querying for that language
|
|
48
52
|
def get_lang(val)
|
|
49
53
|
val = URI.encode(val)
|
|
50
54
|
response = self.class.get("/api/LANG/#{val}")
|
|
@@ -63,12 +67,17 @@ module Cwsrb
|
|
|
63
67
|
public: response['PUBLIC'],
|
|
64
68
|
status: get_lang_status(response['STATUS']),
|
|
65
69
|
registered: Time.at(response['REGISTERED']),
|
|
66
|
-
word_count: response['WORD_COUNT']
|
|
70
|
+
word_count: response['WORD_COUNT'],
|
|
71
|
+
karma: response['KARMA']
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
Cwsrb::Language.new(attribs)
|
|
70
75
|
end
|
|
71
76
|
|
|
77
|
+
# Translates a language type code to a Language::Type class.
|
|
78
|
+
# @param val [String] The one-character code.
|
|
79
|
+
# @return [Language::Type] The translated language type.
|
|
80
|
+
# @raise [APIError] If any error occurred while translating.
|
|
72
81
|
def get_lang_type(val)
|
|
73
82
|
val = URI.encode(val)
|
|
74
83
|
response = self.class.get("/api/LANG/TYPE/#{val}")
|
|
@@ -84,6 +93,10 @@ module Cwsrb
|
|
|
84
93
|
Cwsrb::Language::Type.new(attribs)
|
|
85
94
|
end
|
|
86
95
|
|
|
96
|
+
# Translates a language status code to a Language::Status class.
|
|
97
|
+
# @param val [String] The one-character code.
|
|
98
|
+
# @return [Language::Status] The translated language status.
|
|
99
|
+
# @raise [APIError] If any error occurred while translating.
|
|
87
100
|
def get_lang_status(val)
|
|
88
101
|
val = URI.encode(val)
|
|
89
102
|
response = self.class.get("/api/LANG/STATUS/#{val}")
|
|
@@ -99,6 +112,8 @@ module Cwsrb
|
|
|
99
112
|
Cwsrb::Language::Status.new(attribs)
|
|
100
113
|
end
|
|
101
114
|
|
|
115
|
+
# Gets the API version provided by the API.
|
|
116
|
+
# @return [String] The returned API version.
|
|
102
117
|
def api_version
|
|
103
118
|
self.class.get('/api')['api_ver']
|
|
104
119
|
end
|
data/lib/cwsrb/data.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
module Cwsrb
|
|
2
|
+
CWS_BASE = 'http://conworkshop.com'
|
|
3
|
+
|
|
2
4
|
# The User class represents a member of ConWorkShop.
|
|
3
5
|
class User
|
|
4
6
|
# @return [String, Integer] The User's ID
|
|
@@ -7,7 +9,8 @@ module Cwsrb
|
|
|
7
9
|
# @return [String] The User's name
|
|
8
10
|
attr_reader :name
|
|
9
11
|
|
|
10
|
-
# @return [String] The User's gender, one of "Male", "Female", "Cyborg"
|
|
12
|
+
# @return [String] The User's gender, one of "Male", "Female", "Cyborg"
|
|
13
|
+
# or "Other"
|
|
11
14
|
attr_reader :gender
|
|
12
15
|
|
|
13
16
|
# @return [String] The User's bio, max 1000 characters
|
|
@@ -16,18 +19,23 @@ module Cwsrb
|
|
|
16
19
|
# @return [String] The User's country
|
|
17
20
|
attr_reader :country
|
|
18
21
|
|
|
19
|
-
# @return [Array<(Integer, Integer)>] The User's karma counts; first one
|
|
22
|
+
# @return [Array<(Integer, Integer)>] The User's karma counts; first one
|
|
23
|
+
# is upvotes and second one is downvotes
|
|
20
24
|
attr_reader :karma
|
|
21
25
|
|
|
22
26
|
# Initializes a new User instance with an options hash.
|
|
23
|
-
# @param id [String, Integer] The user's ID: a bunch of numbers that may
|
|
24
|
-
#
|
|
25
|
-
# @param
|
|
26
|
-
# @param
|
|
27
|
+
# @param id [String, Integer] The user's ID: a bunch of numbers that may
|
|
28
|
+
# or may not be prefixed with 'S'. Defaults to an empty string.
|
|
29
|
+
# @param name [String] The user's name. Defaults to an empty string.
|
|
30
|
+
# @param gender [String] The user's gender, one of "Male", "Female",
|
|
31
|
+
# "Cyborg" or "Other". Defaults to "Other".
|
|
32
|
+
# @param bio [String] The user's bio or about section. Defaults to an
|
|
33
|
+
# empty string.
|
|
27
34
|
# @param country [String] The user's country. Defaults to "Unknown".
|
|
28
|
-
# @param karma [Array<(Integer, Integer)>] The user's karma counts
|
|
29
|
-
#
|
|
30
|
-
|
|
35
|
+
# @param karma [Array<(Integer, Integer)>] The user's karma counts.
|
|
36
|
+
# First is upvotes, second is downvotes. Defaults to zero for both.
|
|
37
|
+
# @return [User] a new instance of User
|
|
38
|
+
def initialize(id: '', name: '', gender: 'Other', bio: '', country: 'Unknown', karma: [0, 0])
|
|
31
39
|
@id = id
|
|
32
40
|
@name = name
|
|
33
41
|
@gender = gender
|
|
@@ -36,57 +44,140 @@ module Cwsrb
|
|
|
36
44
|
@karma = karma
|
|
37
45
|
end
|
|
38
46
|
|
|
47
|
+
# Generates a CWS link to this user.
|
|
48
|
+
# @return [String] The generated link.
|
|
49
|
+
def generate_link
|
|
50
|
+
CWS_BASE + "/view_profile.php?m=#{@id}"
|
|
51
|
+
end
|
|
52
|
+
|
|
39
53
|
# @overload inspect
|
|
40
|
-
# @return [String] A more meaningful output than that of the default
|
|
54
|
+
# @return [String] A more meaningful output than that of the default
|
|
55
|
+
# inspect method, with all of User's attributes.
|
|
41
56
|
def inspect
|
|
42
57
|
"<User id=#{@id} name=#{@name} gender=#{gender} bio=#{bio} country=#{country} karma=#{karma}>"
|
|
43
58
|
end
|
|
44
59
|
end
|
|
45
60
|
|
|
61
|
+
# The Language class represents a language of ConWorkShop.
|
|
46
62
|
class Language
|
|
63
|
+
# The Type class represents a language type of ConWorkShop.
|
|
47
64
|
class Type
|
|
65
|
+
# @return [String] The three-character type code.
|
|
48
66
|
attr_reader :code
|
|
67
|
+
|
|
68
|
+
# @return [String] The description for the type.
|
|
49
69
|
attr_reader :desc
|
|
50
70
|
|
|
51
|
-
|
|
71
|
+
# Initializes a new Type instance with an options hash.
|
|
72
|
+
# @param code [String] The three-character type code. Defaults to an
|
|
73
|
+
# empty string.
|
|
74
|
+
# @param desc [String] The description for the type. Defaults to an
|
|
75
|
+
# empty string.
|
|
76
|
+
# @return [Type] A new instance of Type.
|
|
77
|
+
def initialize(code: '', desc: '')
|
|
52
78
|
@code = code
|
|
53
79
|
@desc = desc
|
|
54
80
|
end
|
|
55
81
|
|
|
82
|
+
# @overload inspect
|
|
83
|
+
# @return [String] A more meaningful output than that of the default
|
|
84
|
+
# inspect method, with all of Type's attributes.
|
|
56
85
|
def inspect
|
|
57
86
|
"<Language::Type code=#{@code} desc=#{@desc}>"
|
|
58
87
|
end
|
|
59
88
|
end
|
|
60
89
|
|
|
90
|
+
# The Language::Type class represents a language status of ConWorkShop.
|
|
61
91
|
class Status
|
|
92
|
+
# @return [String] The one-character status code.
|
|
62
93
|
attr_reader :code
|
|
94
|
+
|
|
95
|
+
# @return [String] The description for the status.
|
|
63
96
|
attr_reader :desc
|
|
64
97
|
|
|
65
|
-
|
|
98
|
+
# Initializes a new Status instance with an options hash.
|
|
99
|
+
# @param code [String] The one-character status code. Defaults to an
|
|
100
|
+
# empty string.
|
|
101
|
+
# @param desc [String] The description for the status. Defaults to an
|
|
102
|
+
# empty string.
|
|
103
|
+
def initialize(code: '', desc: '')
|
|
66
104
|
@code = code
|
|
67
105
|
@desc = desc
|
|
68
106
|
end
|
|
69
107
|
|
|
108
|
+
# @overload inspect
|
|
109
|
+
# @return [String] A more meaningful output than that of the default
|
|
110
|
+
# inspect method, with all of Status' attributes.
|
|
70
111
|
def inspect
|
|
71
112
|
"<Language::Status code=#{@code} desc=#{@desc}>"
|
|
72
113
|
end
|
|
73
114
|
end
|
|
74
115
|
|
|
116
|
+
# @return [String] The three-character language code.
|
|
75
117
|
attr_reader :code
|
|
118
|
+
|
|
119
|
+
# @return [String] The language's name.
|
|
76
120
|
attr_reader :name
|
|
121
|
+
|
|
122
|
+
# @return [String] The language's autonym (native name).
|
|
77
123
|
attr_reader :native_name
|
|
124
|
+
|
|
125
|
+
# @return [String] The IPA transcription for the language's {@link native_name}
|
|
78
126
|
attr_reader :ipa
|
|
127
|
+
|
|
128
|
+
# @return [Language::Type] The language's type.
|
|
79
129
|
attr_reader :type
|
|
130
|
+
|
|
131
|
+
# @return [Array<String>] The owner plus shared users of this language.
|
|
132
|
+
# The first element is the original owner.
|
|
80
133
|
attr_reader :owners
|
|
134
|
+
|
|
135
|
+
# @return [String] The overview, about section or bio, of this language.
|
|
81
136
|
attr_reader :overview
|
|
137
|
+
|
|
138
|
+
# @return [Boolean] Whether or not this language's _dictionary_ is public.
|
|
82
139
|
attr_reader :public
|
|
140
|
+
|
|
141
|
+
# @return [Language::Status] The language's status.
|
|
83
142
|
attr_reader :status
|
|
143
|
+
|
|
144
|
+
# @return [Time] The time at which the language was registered.
|
|
84
145
|
attr_reader :registered
|
|
146
|
+
|
|
147
|
+
# @return [Integer] The word count for this language.
|
|
85
148
|
attr_reader :word_count
|
|
86
149
|
|
|
87
|
-
|
|
150
|
+
# @return [Array<(Integer, Integer)>] The language's karma counts;
|
|
151
|
+
# first one is upvotes and second one is downvotes.
|
|
152
|
+
attr_reader :karma
|
|
153
|
+
|
|
154
|
+
# Initializes a new Language instance with an options hash.
|
|
155
|
+
# @param code [String] The three-character language code. Defaults to an
|
|
156
|
+
# empty string.
|
|
157
|
+
# @param name [String] The language's name. Defaults to an empty string.
|
|
158
|
+
# @param native_name [String] The language's autonym (native name).
|
|
159
|
+
# Defaults to an empty string.
|
|
160
|
+
# @param ipa [String] The IPA transcription for the autonym. Defaults to
|
|
161
|
+
# an empty string.
|
|
162
|
+
# @param type [Type] The language's type. Defaults to `nil`.
|
|
163
|
+
# @param owners [Array<String>] The owner plus shared users of this
|
|
164
|
+
# language. The first element must be the original owner.
|
|
165
|
+
# @param overview [String] The overview, about me section, or bio, of
|
|
166
|
+
# this language. Defaults to an empty string.
|
|
167
|
+
# @param public [Boolean] Whether or not this language's dictionary is
|
|
168
|
+
# public. Defaults to `true`.
|
|
169
|
+
# @param status [Status] The language's status. Defaults to `nil`.
|
|
170
|
+
# @param registered [Time] When the language was registered. Defaults to
|
|
171
|
+
# the current time.
|
|
172
|
+
# @param word_count [Integer] The amount of words this language has.
|
|
173
|
+
# Defaults to `0`.
|
|
174
|
+
# @param karma [Array<(Integer, Integer)>] The language's karma counts.
|
|
175
|
+
# The first is upvotes, the second is downvotes. Defaults to zero for
|
|
176
|
+
# both.
|
|
177
|
+
# @return [Language] The new Language instance.
|
|
178
|
+
def initialize(code: '', name: '', native_name: '', ipa: '', type: nil,
|
|
88
179
|
owners: [], overview: '', public: true, status: '',
|
|
89
|
-
registered: Time.now, word_count: 0)
|
|
180
|
+
registered: Time.now, word_count: 0, karma: [0, 0])
|
|
90
181
|
@code = code
|
|
91
182
|
@name = name
|
|
92
183
|
@native_name = native_name
|
|
@@ -98,13 +189,23 @@ module Cwsrb
|
|
|
98
189
|
@status = status
|
|
99
190
|
@registered = registered
|
|
100
191
|
@word_count = word_count
|
|
192
|
+
@karma = karma
|
|
101
193
|
end
|
|
102
194
|
|
|
195
|
+
# Generates a CWS link to this language.
|
|
196
|
+
# @return [String] The generated link.
|
|
197
|
+
def generate_link
|
|
198
|
+
CWS_BASE + "/view_language.php?l=#{@code}"
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# @overload inspect
|
|
202
|
+
# @return [String] A more meaningful output than that of the default
|
|
203
|
+
# inspect method, with all of Language's attributes.
|
|
103
204
|
def inspect
|
|
104
205
|
"<Language code=#{@code} name=#{@name} native_name=#{@native_name} " \
|
|
105
206
|
"ipa=#{@ipa} type=#{@type} owners=#{@owners} overview=#{@overview} " \
|
|
106
207
|
"public=#{@public} status=#{@status} registered=#{@registered} " \
|
|
107
|
-
"word_count=#{@word_count}>"
|
|
208
|
+
"word_count=#{@word_count} karma=#{@karma}>"
|
|
108
209
|
end
|
|
109
210
|
end
|
|
110
211
|
end
|
data/lib/cwsrb/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.5.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-10-
|
|
11
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
127
127
|
version: '0'
|
|
128
128
|
requirements: []
|
|
129
129
|
rubyforge_project:
|
|
130
|
-
rubygems_version: 2.
|
|
130
|
+
rubygems_version: 2.6.7
|
|
131
131
|
signing_key:
|
|
132
132
|
specification_version: 4
|
|
133
133
|
summary: Access Conworkshop's API with Ruby.
|