Class: JncApi::Api
- Inherits:
-
Object
- Object
- JncApi::Api
- Defined in:
- lib/jnc_api.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #completion(part_id, percent_completed = 1.00) ⇒ Object
- #embed(part_id) ⇒ Object
- #feed(user_id) ⇒ Object
-
#initialize(routes: V2_ROUTES, token: nil) ⇒ Api
constructor
A new instance of Api.
-
#manga_parts(part_id) ⇒ Object
we can’t seem to use bearer tokens for the manga endpoints.
- #me ⇒ Object
- #parts_data(slug) ⇒ Object
- #series_aggregate(slug) ⇒ Object
- #series_list(limit: 500, skip: 0) ⇒ Object
-
#webpub(uuid, ngtoken) ⇒ Object
this endpoint seems to be on a CDN without need for authorization likely for cheaper static hosting (as long as the locations are difficult to guess such as uuid).
Constructor Details
#initialize(routes: V2_ROUTES, token: nil) ⇒ Api
Returns a new instance of Api.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jnc_api.rb', line 74 def initialize(routes: V2_ROUTES, token: nil) @routes = routes @token = token @default_headers = { "User-Agent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0", "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Language" => "en-US,en;q=0.5", "Content-Type" => "application/json" } @bearer = {"Authorization" => "Bearer #{@token}"} end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
52 53 54 |
# File 'lib/jnc_api.rb', line 52 def token @token end |
Class Method Details
.login(login, password, routes = V2_ROUTES) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jnc_api.rb', line 54 def self.login(login, password, routes = V2_ROUTES) response = HTTParty.post( routes[:login] + "?format=json", body: JSON.generate( {"login" => login, "password" => password, "slim" => true} ), headers: { "Content-Type" => "application/json" } ) if response.success? new(token: response["id"]) else raise Error.new(response.inspect) end end |
Instance Method Details
#completion(part_id, percent_completed = 1.00) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/jnc_api.rb', line 168 def completion(part_id, percent_completed = 1.00) response = HTTParty.put( @routes[:completion] + "/#{part_id}", body: percent_completed.to_s, headers: @default_headers.merge(@bearer) ) if response.success? response.body else raise Error.new(response.inspect) end end |
#embed(part_id) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/jnc_api.rb', line 154 def (part_id) response = HTTParty.get( @routes[:embed] + "/#{part_id}/data.xhtml", headers: @default_headers.merge(@bearer) ) if response.success? response.body else raise Error.new(response.inspect) end end |
#feed(user_id) ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/jnc_api.rb', line 130 def feed(user_id) response = HTTParty.get(@routes[:feed] + "/#{user_id}.json") if response.success? response.body else raise Error.new(response.inspect) end end |
#manga_parts(part_id) ⇒ Object
we can’t seem to use bearer tokens for the manga endpoints
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/jnc_api.rb', line 184 def manga_parts(part_id) response = HTTParty.get( @routes[:manga_parts] + "/#{part_id}/token?access_token=#{@token}", headers: @default_headers ) if response.success? response.body else raise Error.new(response.inspect) end end |
#me ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/jnc_api.rb', line 116 def me response = HTTParty.get( @routes[:me] + "?format=json", headers: @default_headers.merge(@bearer) ) if response.success? response.body else raise Error.new(response.inspect) end end |
#parts_data(slug) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/jnc_api.rb', line 140 def parts_data(slug) response = HTTParty.get( @routes[:parts] + "/#{slug}/data?format=json", headers: @default_headers.merge(@bearer) ) if response.success? response.body else raise Error.new(response.inspect) end end |
#series_aggregate(slug) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/jnc_api.rb', line 102 def series_aggregate(slug) response = HTTParty.get( @routes[:series] + "/#{slug}/aggregate?format=json", headers: @default_headers.merge(@bearer) ) if response.success? response.body else raise Error.new(response.inspect) end end |
#series_list(limit: 500, skip: 0) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jnc_api.rb', line 88 def series_list(limit: 500, skip: 0) response = HTTParty.get( @routes[:series] + "?format=json&limit=#{limit}&skip=#{skip}", headers: @default_headers.merge(@bearer) ) if response.success? response.body else raise Error.new(response.inspect) end end |
#webpub(uuid, ngtoken) ⇒ Object
this endpoint seems to be on a CDN without need for authorization likely for cheaper static hosting (as long as the locations are difficult to guess such as uuid)
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/jnc_api.rb', line 201 def webpub(uuid, ngtoken) response = HTTParty.post( @routes[:webpub] + "/#{uuid}", body: ngtoken, headers: @default_headers ) if response.success? response.body else raise Error.new(response.inspect) end end |