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: V1_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: V1_ROUTES, token: nil) ⇒ Api
Returns a new instance of Api.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jnc_api.rb', line 61 def initialize(routes: V1_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.
39 40 41 |
# File 'lib/jnc_api.rb', line 39 def token @token end |
Class Method Details
.login(login, password, routes = V1_ROUTES) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jnc_api.rb', line 41 def self.login(login, password, routes = V1_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
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/jnc_api.rb', line 155 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
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/jnc_api.rb', line 141 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
117 118 119 120 121 122 123 124 125 |
# File 'lib/jnc_api.rb', line 117 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
171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/jnc_api.rb', line 171 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
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/jnc_api.rb', line 103 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
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/jnc_api.rb', line 127 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
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/jnc_api.rb', line 89 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
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/jnc_api.rb', line 75 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)
188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/jnc_api.rb', line 188 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 |