renshuu 0.1.0 → 0.2.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/.rubocop.yml +4 -0
- data/CHANGELOG.md +8 -0
- data/README.md +38 -0
- data/lib/renshuu/models/grammar.rb +75 -0
- data/lib/renshuu/models/kanji.rb +126 -0
- data/lib/renshuu/models/model.rb +2 -8
- data/lib/renshuu/models/profile.rb +158 -0
- data/lib/renshuu/models/sentence.rb +56 -0
- data/lib/renshuu/models/types.rb +27 -0
- data/lib/renshuu/models/user_data.rb +53 -0
- data/lib/renshuu/models/word.rb +83 -0
- data/lib/renshuu/models.rb +9 -1
- data/lib/renshuu/version.rb +1 -1
- data/lib/renshuu.rb +1 -1
- metadata +13 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a43b493faf4ee0d7165c0a6a054f04a1f2e50ecb60d81c1e9226bea9c6be3643
|
|
4
|
+
data.tar.gz: 71e85c4b84336960eddd66b525167528495ba04fb26f340d6a022aa3bf5d5cff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a848a7d5c6615157835467a7e564bfe201c13dfbf9f8ffc4ea26d6f15b3f292df68f042f3b0dd352391a8d6ba1577fdd2c68635946cd811aae15ba06b94ad89e
|
|
7
|
+
data.tar.gz: e3eed0edab20ad32adba4042a6a4d4728c23fceb035ac2ba81704a64952e5aa1ff7ac6026ae2d7ac2bfbc59d6d5cf5aa7ebaa0b73893ecbd16dec7196d33b146
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -61,6 +61,44 @@ Renshuu::Kanji.search('たべる')
|
|
|
61
61
|
Renshuu::Kanji.get('紅')
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
### Vocabulary dictionary
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
# Searches the word dictionary
|
|
68
|
+
Renshuu::Word.search('to eat')
|
|
69
|
+
Renshuu::Word.search('taberu')
|
|
70
|
+
Renshuu::Word.search('食べる')
|
|
71
|
+
|
|
72
|
+
# Retrieves a word from its identifier
|
|
73
|
+
Renshuu::Word.get(370)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Grammar dictionary
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
# Searches the grammar dictionary
|
|
80
|
+
Renshuu::Grammar.search('without')
|
|
81
|
+
Renshuu::Grammar.search('ましょう')
|
|
82
|
+
|
|
83
|
+
# Retrieves a specific grammar entry from its identifier
|
|
84
|
+
Renshuu::Grammar.get(6)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Sentence dictionary
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
# Searches the sentence dictionary
|
|
91
|
+
Renshuu::Sentence.search('to eat')
|
|
92
|
+
Renshuu::Sentence.search('ケーキ')
|
|
93
|
+
|
|
94
|
+
# Retrieves sentences for a given word.
|
|
95
|
+
Renshuu::Sentence.word_search(370)
|
|
96
|
+
|
|
97
|
+
# Syntactic sugar for `Renshuu::Word`.
|
|
98
|
+
word = Renshuu::Word.get(370)
|
|
99
|
+
word.sentences
|
|
100
|
+
```
|
|
101
|
+
|
|
64
102
|
## Development
|
|
65
103
|
|
|
66
104
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Renshuu
|
|
4
|
+
##
|
|
5
|
+
# Model class for grammar entries.
|
|
6
|
+
class Grammar < Model
|
|
7
|
+
##
|
|
8
|
+
# Searches the grammar dictionary.
|
|
9
|
+
#
|
|
10
|
+
# @param [String] value
|
|
11
|
+
#
|
|
12
|
+
# @return [Array<Grammar>]
|
|
13
|
+
def self.search(value)
|
|
14
|
+
Renshuu.client.query(:get, 'v1/grammar/search', params: { value: })
|
|
15
|
+
.fetch(:grammar).map { new(_1) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
# Retrieves a grammar entry fom the dictionary.
|
|
20
|
+
#
|
|
21
|
+
# @param [Integer] id
|
|
22
|
+
#
|
|
23
|
+
# @return [Grammar]
|
|
24
|
+
def self.get(id)
|
|
25
|
+
Renshuu.client.query(:get, "v1/grammar/#{id}").then { new(_1) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# @!attribute [r] id
|
|
30
|
+
# @return [String]
|
|
31
|
+
attribute :id, Types::String
|
|
32
|
+
##
|
|
33
|
+
# @!attribute [r] title_english
|
|
34
|
+
# @return [String]
|
|
35
|
+
attribute :title_english, Types::String
|
|
36
|
+
##
|
|
37
|
+
# @!attribute [r] title_japanese
|
|
38
|
+
# @return [String]
|
|
39
|
+
attribute :title_japanese, Types::String
|
|
40
|
+
##
|
|
41
|
+
# @!attribute [r] meaning
|
|
42
|
+
# @return [Hash{String => String}]
|
|
43
|
+
attribute :meaning, Types::Hash.map(Types::String, Types::String)
|
|
44
|
+
##
|
|
45
|
+
# @!attribute [r] meaning_long
|
|
46
|
+
# @return [Hash{String => String}]
|
|
47
|
+
attribute :meaning_long, Types::Hash.map(Types::String, Types::String)
|
|
48
|
+
|
|
49
|
+
##
|
|
50
|
+
# Model class for grammar models.
|
|
51
|
+
class Model < Model
|
|
52
|
+
##
|
|
53
|
+
# @!attribute [r] japanese
|
|
54
|
+
# @return [String]
|
|
55
|
+
attribute :japanese, Types::String
|
|
56
|
+
##
|
|
57
|
+
# @!attribute [r] hiragana
|
|
58
|
+
# @return [String]
|
|
59
|
+
attribute :hiragana, Types::String
|
|
60
|
+
##
|
|
61
|
+
# @!attribute [r] meanings
|
|
62
|
+
# @return [Hash{String => String}]
|
|
63
|
+
attribute :meanings, Types::Hash.map(Types::String, Types::String)
|
|
64
|
+
end
|
|
65
|
+
##
|
|
66
|
+
# @!attribute [r] models
|
|
67
|
+
# @return [Array<Model>]
|
|
68
|
+
attribute :models, Types::Array.of(Model)
|
|
69
|
+
|
|
70
|
+
##
|
|
71
|
+
# @!attribute [r] user_data
|
|
72
|
+
# @return [UserData]
|
|
73
|
+
attribute :user_data, UserData
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/renshuu/models/kanji.rb
CHANGED
|
@@ -29,5 +29,131 @@ module Renshuu
|
|
|
29
29
|
body = Renshuu.client.query(:get, "v1/kanji/#{cgi_character}")
|
|
30
30
|
new(body)
|
|
31
31
|
end
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# @!attribute [r] id
|
|
35
|
+
# @return [String]
|
|
36
|
+
attribute :id, Types::String
|
|
37
|
+
##
|
|
38
|
+
# @!attribute [r] kanji
|
|
39
|
+
# @return [String]
|
|
40
|
+
attribute :kanji, Types::String
|
|
41
|
+
##
|
|
42
|
+
# @!attribute [r] definition
|
|
43
|
+
# @return [String]
|
|
44
|
+
attribute :definition, Types::String
|
|
45
|
+
##
|
|
46
|
+
# @!attribute [r] scount
|
|
47
|
+
# @return [Integer, nil]
|
|
48
|
+
attribute? :scount, Types::Integer
|
|
49
|
+
alias stroke_count scount
|
|
50
|
+
##
|
|
51
|
+
# @!attribute [r] radical
|
|
52
|
+
# @return [String, nil]
|
|
53
|
+
attribute? :radical, Types::String
|
|
54
|
+
##
|
|
55
|
+
# @!attribute [r] radical_name
|
|
56
|
+
# @return [String, nil]
|
|
57
|
+
attribute? :radical_name, Types::String
|
|
58
|
+
##
|
|
59
|
+
# @!attribute [r] onyomi
|
|
60
|
+
# @return [String, nil]
|
|
61
|
+
attribute? :onyomi, Types::String
|
|
62
|
+
##
|
|
63
|
+
# @!attribute [r] kunyomi
|
|
64
|
+
# @return [String, nil]
|
|
65
|
+
attribute? :kunyomi, Types::String
|
|
66
|
+
##
|
|
67
|
+
# @!attribute [r] kanken
|
|
68
|
+
# @return [String, nil]
|
|
69
|
+
attribute? :kanken, Types::String
|
|
70
|
+
##
|
|
71
|
+
# @!attribute [r] jlpt
|
|
72
|
+
# @return [String, nil]
|
|
73
|
+
attribute? :jlpt, Types::String
|
|
74
|
+
|
|
75
|
+
##
|
|
76
|
+
# Model class for kanji's related words.
|
|
77
|
+
class RelatedWord < Model
|
|
78
|
+
##
|
|
79
|
+
# @!attribute [r] reading
|
|
80
|
+
# @return [String]
|
|
81
|
+
attribute :reading, Types::String
|
|
82
|
+
|
|
83
|
+
##
|
|
84
|
+
# Model class for kanji's related words' word.
|
|
85
|
+
class Word < Model
|
|
86
|
+
##
|
|
87
|
+
# @!attribute [r] def
|
|
88
|
+
# @return [String]
|
|
89
|
+
attribute :def, Types::String
|
|
90
|
+
##
|
|
91
|
+
# @!attribute [r] term
|
|
92
|
+
# @return [String]
|
|
93
|
+
attribute :term, Types::String
|
|
94
|
+
end
|
|
95
|
+
attribute :words, Types::Array.of(Word)
|
|
96
|
+
end
|
|
97
|
+
##
|
|
98
|
+
# @!attribute [r] rwords
|
|
99
|
+
# @return [Array<RelatedWord>, nil]
|
|
100
|
+
attribute? :rwords, Types::Array.of(RelatedWord)
|
|
101
|
+
##
|
|
102
|
+
# @!attribute [r] user_data
|
|
103
|
+
# @return [UserData, nil]
|
|
104
|
+
attribute? :user_data, UserData
|
|
105
|
+
|
|
106
|
+
##
|
|
107
|
+
# Model class for kanji presence.
|
|
108
|
+
class Presence < Model
|
|
109
|
+
##
|
|
110
|
+
# Model class for kanji schedule presence.
|
|
111
|
+
class Schedule < Model
|
|
112
|
+
##
|
|
113
|
+
# @!attribute [r] sched_id
|
|
114
|
+
# @return [String]
|
|
115
|
+
attribute :sched_id, Types::String
|
|
116
|
+
alias schedule_id sched_id
|
|
117
|
+
##
|
|
118
|
+
# @!attribute [r] name
|
|
119
|
+
# @return [String]
|
|
120
|
+
attribute :name, Types::String
|
|
121
|
+
##
|
|
122
|
+
# @!attribute [r] has_word
|
|
123
|
+
# @return [Boolean]
|
|
124
|
+
attribute :has_word, Types::Params::Bool
|
|
125
|
+
end
|
|
126
|
+
##
|
|
127
|
+
# @!attribute [r] scheds
|
|
128
|
+
# @return [Array<Schedule>]
|
|
129
|
+
attribute :scheds, Types::Array.of(Schedule)
|
|
130
|
+
alias schedules scheds
|
|
131
|
+
|
|
132
|
+
##
|
|
133
|
+
# Model class for kanji list presence.
|
|
134
|
+
class List < Model
|
|
135
|
+
##
|
|
136
|
+
# @!attribute [r] list_id
|
|
137
|
+
# @return [String]
|
|
138
|
+
attribute :list_id, Types::String
|
|
139
|
+
##
|
|
140
|
+
# @!attribute [r] name
|
|
141
|
+
# @return [String]
|
|
142
|
+
attribute :name, Types::String
|
|
143
|
+
##
|
|
144
|
+
# @!attribute [r] set_name
|
|
145
|
+
# @return [String, nil]
|
|
146
|
+
attribute? :set_name, Types::String
|
|
147
|
+
##
|
|
148
|
+
# @!attribute [r] has_word
|
|
149
|
+
# @return [Boolean]
|
|
150
|
+
attribute :has_word, Types::Params::Bool
|
|
151
|
+
end
|
|
152
|
+
##
|
|
153
|
+
# @!attribute [r] lists
|
|
154
|
+
# @return [Array<List>]
|
|
155
|
+
attribute :lists, Types::Array.of(List)
|
|
156
|
+
end
|
|
157
|
+
attribute? :presence, Presence
|
|
32
158
|
end
|
|
33
159
|
end
|
data/lib/renshuu/models/model.rb
CHANGED
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
module Renshuu
|
|
4
4
|
##
|
|
5
5
|
# Base class for model objects.
|
|
6
|
-
class Model <
|
|
7
|
-
|
|
8
|
-
# Default options for new objects.
|
|
9
|
-
#
|
|
10
|
-
# @return [Hash{Symbol => Object}]
|
|
11
|
-
def self.default_options
|
|
12
|
-
super.merge(raise_on_missing: true, recurse_over_arrays: true)
|
|
13
|
-
end
|
|
6
|
+
class Model < Dry::Struct
|
|
7
|
+
transform_keys { _1.to_s.underscore.to_sym }
|
|
14
8
|
end
|
|
15
9
|
end
|
|
@@ -12,5 +12,163 @@ module Renshuu
|
|
|
12
12
|
body = Renshuu.client.query(:get, 'v1/profile')
|
|
13
13
|
new(body)
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# @!attribute [r] id
|
|
18
|
+
# @return [String]
|
|
19
|
+
attribute :id, Types::String
|
|
20
|
+
##
|
|
21
|
+
# @!attribute [r] real_name
|
|
22
|
+
# @return [String]
|
|
23
|
+
attribute :real_name, Types::String
|
|
24
|
+
##
|
|
25
|
+
# @!attribute [r] adventure_level
|
|
26
|
+
# @return [String]
|
|
27
|
+
attribute :adventure_level, Types::String
|
|
28
|
+
##
|
|
29
|
+
# @!attribute [r] user_length
|
|
30
|
+
# @return [String]
|
|
31
|
+
attribute :user_length, Types::String
|
|
32
|
+
##
|
|
33
|
+
# @!attribute [r] kao
|
|
34
|
+
# @return [URI]
|
|
35
|
+
attribute :kao, Types::URI
|
|
36
|
+
|
|
37
|
+
##
|
|
38
|
+
# Model class for user study counts.
|
|
39
|
+
class StudyCount < Model
|
|
40
|
+
##
|
|
41
|
+
# @!attribute [r] today_all
|
|
42
|
+
# @return [Integer]
|
|
43
|
+
attribute :today_all, Types::Integer
|
|
44
|
+
##
|
|
45
|
+
# @!attribute [r] today_grammar
|
|
46
|
+
# @return [Integer]
|
|
47
|
+
attribute :today_grammar, Types::Integer
|
|
48
|
+
##
|
|
49
|
+
# @!attribute [r] today_vocab
|
|
50
|
+
# @return [Integer]
|
|
51
|
+
attribute :today_vocab, Types::Integer
|
|
52
|
+
##
|
|
53
|
+
# @!attribute [r] today_kanji
|
|
54
|
+
# @return [Integer]
|
|
55
|
+
attribute :today_kanji, Types::Integer
|
|
56
|
+
##
|
|
57
|
+
# @!attribute [r] today_sent
|
|
58
|
+
# @return [Integer]
|
|
59
|
+
attribute :today_sent, Types::Integer
|
|
60
|
+
##
|
|
61
|
+
# @!attribute [r] today_aconj
|
|
62
|
+
# @return [Integer]
|
|
63
|
+
attribute :today_aconj, Types::Integer
|
|
64
|
+
##
|
|
65
|
+
# @!attribute [r] today_conj
|
|
66
|
+
# @return [Integer]
|
|
67
|
+
attribute :today_conj, Types::Integer
|
|
68
|
+
##
|
|
69
|
+
# @!attribute [r] total
|
|
70
|
+
# @return [Integer]
|
|
71
|
+
attribute :total, Types::Integer
|
|
72
|
+
##
|
|
73
|
+
# @!attribute [r] total_vocab
|
|
74
|
+
# @return [Integer]
|
|
75
|
+
attribute :total_vocab, Types::Integer
|
|
76
|
+
##
|
|
77
|
+
# @!attribute [r] total_kanji
|
|
78
|
+
# @return [Integer]
|
|
79
|
+
attribute :total_kanji, Types::Integer
|
|
80
|
+
##
|
|
81
|
+
# @!attribute [r] total_grammar
|
|
82
|
+
# @return [Integer]
|
|
83
|
+
attribute :total_grammar, Types::Integer
|
|
84
|
+
##
|
|
85
|
+
# @!attribute [r] total_sent
|
|
86
|
+
# @return [Integer]
|
|
87
|
+
attribute :total_sent, Types::Integer
|
|
88
|
+
end
|
|
89
|
+
##
|
|
90
|
+
# @!attribute [r] studied
|
|
91
|
+
# @return [StudyCount]
|
|
92
|
+
attribute :studied, StudyCount
|
|
93
|
+
alias study_count studied
|
|
94
|
+
|
|
95
|
+
##
|
|
96
|
+
# Model class for profile JLPT progress.
|
|
97
|
+
class Progress < Model
|
|
98
|
+
##
|
|
99
|
+
# @!attribute [r] n1
|
|
100
|
+
# @return [Integer]
|
|
101
|
+
attribute :n1, Types::Integer
|
|
102
|
+
##
|
|
103
|
+
# @!attribute [r] n2
|
|
104
|
+
# @return [Integer]
|
|
105
|
+
attribute :n2, Types::Integer
|
|
106
|
+
##
|
|
107
|
+
# @!attribute [r] n3
|
|
108
|
+
# @return [Integer]
|
|
109
|
+
attribute :n3, Types::Integer
|
|
110
|
+
##
|
|
111
|
+
# @!attribute [r] n4
|
|
112
|
+
# @return [Integer]
|
|
113
|
+
attribute :n4, Types::Integer
|
|
114
|
+
##
|
|
115
|
+
# @!attribute [r] n5
|
|
116
|
+
# @return [Integer]
|
|
117
|
+
attribute :n5, Types::Integer
|
|
118
|
+
end
|
|
119
|
+
##
|
|
120
|
+
# @!attribute [r] level_progress_percs
|
|
121
|
+
# @return [Hash{String => Progress}]
|
|
122
|
+
attribute :level_progress_percs, Types::Hash.map(Types::String, Progress)
|
|
123
|
+
|
|
124
|
+
##
|
|
125
|
+
# Model class for profile study streaks.
|
|
126
|
+
class Streak < Model
|
|
127
|
+
##
|
|
128
|
+
# @!attribute [r] correct_in_a_row
|
|
129
|
+
# @return [Integer]
|
|
130
|
+
attribute :correct_in_a_row, Types::Integer
|
|
131
|
+
##
|
|
132
|
+
# @!attribute [r] correct_in_a_row_alltime
|
|
133
|
+
# @return [Integer]
|
|
134
|
+
attribute :correct_in_a_row_alltime, Types::Integer
|
|
135
|
+
##
|
|
136
|
+
# @!attribute [r] days_studied_in_a_row
|
|
137
|
+
# @return [Integer]
|
|
138
|
+
attribute :days_studied_in_a_row, Types::Integer
|
|
139
|
+
##
|
|
140
|
+
# @!attribute [r] days_studied_in_a_row_alltime
|
|
141
|
+
# @return [Integer]
|
|
142
|
+
attribute :days_studied_in_a_row_alltime, Types::Integer
|
|
143
|
+
end
|
|
144
|
+
##
|
|
145
|
+
# @!attribute [r] streaks
|
|
146
|
+
# @return [Hash{String => Streak}]
|
|
147
|
+
attribute :streaks, Types::Hash.map(Types::String, Streak)
|
|
148
|
+
|
|
149
|
+
##
|
|
150
|
+
# Model class for profile API usage.
|
|
151
|
+
class APIUsage < Model
|
|
152
|
+
##
|
|
153
|
+
# @!attribute [r] calls_today
|
|
154
|
+
# @return [Integer]
|
|
155
|
+
attribute :calls_today, Types::Integer
|
|
156
|
+
##
|
|
157
|
+
# @!attribute [r] daily_allowance
|
|
158
|
+
# @return [Integer]
|
|
159
|
+
attribute :daily_allowance, Types::Integer
|
|
160
|
+
|
|
161
|
+
##
|
|
162
|
+
# Number of API calls remaining in today's quota.
|
|
163
|
+
#
|
|
164
|
+
# @return [Integer]
|
|
165
|
+
def remaining_today
|
|
166
|
+
daily_allowance - calls_today
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
##
|
|
170
|
+
# @!attribute [r] api_usage
|
|
171
|
+
# @return [APIUsage]
|
|
172
|
+
attribute :api_usage, APIUsage
|
|
15
173
|
end
|
|
16
174
|
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Renshuu
|
|
4
|
+
##
|
|
5
|
+
# Model class for sentences.
|
|
6
|
+
#
|
|
7
|
+
# @see https://api.renshuu.org/docs/#/Sentence
|
|
8
|
+
class Sentence < Model
|
|
9
|
+
##
|
|
10
|
+
# Searches sentences in Renshuu's dictionary.
|
|
11
|
+
#
|
|
12
|
+
# @param [String] value
|
|
13
|
+
#
|
|
14
|
+
# @return [Array<Sentence>]
|
|
15
|
+
#
|
|
16
|
+
# @see https://api.renshuu.org/docs/#/Sentence/get_reibun_search
|
|
17
|
+
def self.search(value)
|
|
18
|
+
Renshuu.client.query(:get, 'v1/reibun/search', params: { value: })
|
|
19
|
+
.fetch(:reibuns).map { new(_1) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
# Retrieves sentences from Renshuu's dictionary for a specific word.
|
|
24
|
+
#
|
|
25
|
+
# @param [Word, Integer] word
|
|
26
|
+
#
|
|
27
|
+
# @return [Array<Sentence>]
|
|
28
|
+
#
|
|
29
|
+
# @see https://api.renshuu.org/docs/#/Sentence/get_reibun_search__word_id_
|
|
30
|
+
def self.word_search(word)
|
|
31
|
+
identifier = case word
|
|
32
|
+
when Integer then word
|
|
33
|
+
else word.id
|
|
34
|
+
end
|
|
35
|
+
Renshuu.client.query(:get, "v1/reibun/search/#{identifier}")
|
|
36
|
+
.fetch(:reibuns).map { new(_1) }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
# @!attribute [r] id
|
|
41
|
+
# @return [String]
|
|
42
|
+
attribute :id, Types::String
|
|
43
|
+
##
|
|
44
|
+
# @!attribute [r] japanese
|
|
45
|
+
# @return [String]
|
|
46
|
+
attribute :japanese, Types::String
|
|
47
|
+
##
|
|
48
|
+
# @!attribute [r] hiragana
|
|
49
|
+
# @return [String]
|
|
50
|
+
attribute :hiragana, Types::String
|
|
51
|
+
##
|
|
52
|
+
# @!attribute [r] meaning
|
|
53
|
+
# @return [Hash{String => String}]
|
|
54
|
+
attribute :meaning, Types::Hash.map(Types::String, Types::String)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Renshuu
|
|
4
|
+
##
|
|
5
|
+
# Module for type values.
|
|
6
|
+
module Types
|
|
7
|
+
include Dry.Types(default: :coercible)
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Dry type for dates.
|
|
11
|
+
Date = Constructor(::Date) do |date|
|
|
12
|
+
if date.is_a?(::Date)
|
|
13
|
+
date
|
|
14
|
+
elsif date == 'Not yet'
|
|
15
|
+
nil
|
|
16
|
+
else
|
|
17
|
+
::Date.parse(date)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# Dry type for URIs.
|
|
23
|
+
URI = Constructor(URI) do |uri|
|
|
24
|
+
::URI.parse(uri)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Renshuu
|
|
4
|
+
##
|
|
5
|
+
# Model class for user data.
|
|
6
|
+
class UserData < Model
|
|
7
|
+
##
|
|
8
|
+
# @!attribute [r] correct_count
|
|
9
|
+
# @return [Integer]
|
|
10
|
+
attribute :correct_count, Types::Integer
|
|
11
|
+
##
|
|
12
|
+
# @!attribute [r] missed_count
|
|
13
|
+
# @return [Integer]
|
|
14
|
+
attribute :missed_count, Types::Integer
|
|
15
|
+
##
|
|
16
|
+
# @!attribute [r] mastery_avg_perc
|
|
17
|
+
# @return [Integer]
|
|
18
|
+
attribute :mastery_avg_perc, Types::Integer
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# Model class for user data study vectors.
|
|
22
|
+
class StudyVector < Model
|
|
23
|
+
##
|
|
24
|
+
# @!attribute [r] name
|
|
25
|
+
# @return [String]
|
|
26
|
+
attribute :name, Types::String
|
|
27
|
+
##
|
|
28
|
+
# @!attribute [r] correct_count
|
|
29
|
+
# @return [Integer]
|
|
30
|
+
attribute :correct_count, Types::Integer
|
|
31
|
+
##
|
|
32
|
+
# @!attribute [r] missed_count
|
|
33
|
+
# @return [Integer]
|
|
34
|
+
attribute :missed_count, Types::Integer
|
|
35
|
+
##
|
|
36
|
+
# @!attribute [r] mastery_perc
|
|
37
|
+
# @return [Integer]
|
|
38
|
+
attribute :mastery_perc, Types::Integer
|
|
39
|
+
##
|
|
40
|
+
# @!attribute [r] last_quizzed
|
|
41
|
+
# @return [Date]
|
|
42
|
+
attribute :last_quizzed, Types::Date
|
|
43
|
+
##
|
|
44
|
+
# @!attribute [r] next_quiz
|
|
45
|
+
# @return [Date]
|
|
46
|
+
attribute :next_quiz, Types::Date
|
|
47
|
+
end
|
|
48
|
+
##
|
|
49
|
+
# @!attribute [r] study_vectors
|
|
50
|
+
# @return [Hash{String => StudyVector}]
|
|
51
|
+
attribute? :study_vectors, Types::Hash.map(Types::String, StudyVector)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Renshuu
|
|
4
|
+
##
|
|
5
|
+
# Model class for words and vocabulary.
|
|
6
|
+
#
|
|
7
|
+
# @see https://api.renshuu.org/docs/#/Vocabulary
|
|
8
|
+
class Word < Model
|
|
9
|
+
##
|
|
10
|
+
# Searches the Renshuu vocabulary dictionary.
|
|
11
|
+
#
|
|
12
|
+
# @param [String] value
|
|
13
|
+
#
|
|
14
|
+
# @return [Array<Word>]
|
|
15
|
+
def self.search(value)
|
|
16
|
+
body = Renshuu.client.query(:get, 'v1/word/search', params: { value: })
|
|
17
|
+
|
|
18
|
+
body.fetch(:words).map { new(_1) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# Retrieves a word from the dictionary by its identifier.
|
|
23
|
+
#
|
|
24
|
+
# @param [Integer] id
|
|
25
|
+
#
|
|
26
|
+
# @return [Word]
|
|
27
|
+
def self.get(id)
|
|
28
|
+
body = Renshuu.client.query(:get, "v1/word/#{id}")
|
|
29
|
+
|
|
30
|
+
body.fetch(:words).first.then { new(_1) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# @!attribute [r] id
|
|
35
|
+
# @return [String]
|
|
36
|
+
attribute :id, Types::String
|
|
37
|
+
##
|
|
38
|
+
# @!attribute [r] kanji_full
|
|
39
|
+
# @return [String]
|
|
40
|
+
attribute :kanji_full, Types::String
|
|
41
|
+
##
|
|
42
|
+
# @!attribute [r] hiragana_full
|
|
43
|
+
# @return [String]
|
|
44
|
+
attribute :hiragana_full, Types::String
|
|
45
|
+
##
|
|
46
|
+
# @!attribute [r] pic
|
|
47
|
+
# @return [Array<URI>, nil]
|
|
48
|
+
attribute? :pic, Types::Array.of(Types::URI)
|
|
49
|
+
alias pictures pic
|
|
50
|
+
##
|
|
51
|
+
# @!attribute [r] markers
|
|
52
|
+
# @return [Array<String>]
|
|
53
|
+
attribute :markers, Types::Array.of(Types::String)
|
|
54
|
+
##
|
|
55
|
+
# @!attribute [r] pitch
|
|
56
|
+
# @return [Array<String>]
|
|
57
|
+
attribute :pitch, Types::Array.of(Types::String)
|
|
58
|
+
##
|
|
59
|
+
# @!attribute [r] typeofspeech
|
|
60
|
+
# @return [String]
|
|
61
|
+
attribute :typeofspeech, Types::String
|
|
62
|
+
alias type_of_speech typeofspeech
|
|
63
|
+
##
|
|
64
|
+
# @!attribute [r] def
|
|
65
|
+
# @return [Array<String>]
|
|
66
|
+
attribute :def, Types::Array.of(Types::String)
|
|
67
|
+
|
|
68
|
+
##
|
|
69
|
+
# @!attribute [r] user_data
|
|
70
|
+
# @return [UserData, nil]
|
|
71
|
+
attribute? :user_data, UserData
|
|
72
|
+
|
|
73
|
+
##
|
|
74
|
+
# Retrieves sentences using this word from the dictionary.
|
|
75
|
+
#
|
|
76
|
+
# @return [Array<Sentence>]
|
|
77
|
+
#
|
|
78
|
+
# @see Sentence.word_search
|
|
79
|
+
def sentences
|
|
80
|
+
Sentence.word_search(self)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
data/lib/renshuu/models.rb
CHANGED
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
module Renshuu # rubocop:disable Style/Documentation
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
+
# Types
|
|
7
|
+
require_relative 'models/types'
|
|
8
|
+
|
|
6
9
|
# Base class
|
|
7
10
|
require_relative 'models/model'
|
|
8
11
|
|
|
9
|
-
# Other models
|
|
12
|
+
# Other models (respect blank lines for dependency order)
|
|
13
|
+
require_relative 'models/user_data'
|
|
14
|
+
|
|
15
|
+
require_relative 'models/grammar'
|
|
10
16
|
require_relative 'models/kanji'
|
|
11
17
|
require_relative 'models/profile'
|
|
18
|
+
require_relative 'models/sentence'
|
|
19
|
+
require_relative 'models/word'
|
data/lib/renshuu/version.rb
CHANGED
data/lib/renshuu.rb
CHANGED
metadata
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: renshuu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Richard Degenne
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-12-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: dry-struct
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.
|
|
19
|
+
version: '1.8'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1.
|
|
26
|
+
version: '1.8'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: httpx
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '1.5'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '1.5'
|
|
41
41
|
description: Ruby wrapper for the Renshuu API.
|
|
42
42
|
email:
|
|
43
43
|
- hello@richarddegenne.fr
|
|
@@ -60,9 +60,14 @@ files:
|
|
|
60
60
|
- lib/renshuu/client.rb
|
|
61
61
|
- lib/renshuu/configuration.rb
|
|
62
62
|
- lib/renshuu/models.rb
|
|
63
|
+
- lib/renshuu/models/grammar.rb
|
|
63
64
|
- lib/renshuu/models/kanji.rb
|
|
64
65
|
- lib/renshuu/models/model.rb
|
|
65
66
|
- lib/renshuu/models/profile.rb
|
|
67
|
+
- lib/renshuu/models/sentence.rb
|
|
68
|
+
- lib/renshuu/models/types.rb
|
|
69
|
+
- lib/renshuu/models/user_data.rb
|
|
70
|
+
- lib/renshuu/models/word.rb
|
|
66
71
|
- lib/renshuu/version.rb
|
|
67
72
|
- renshuu.code-workspace
|
|
68
73
|
- sample.env
|