Class: Kiita::API
- Inherits:
-
Object
- Object
- Kiita::API
- Extended by:
- Errors::HandlerMethods
- Defined in:
- lib/kiita/api.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
- .authenticate(url_name, password) ⇒ Object
- .delete(path, options = {}) ⇒ Object
- .get(path, options = {}) ⇒ Object
- .item(uuid) ⇒ Object
- .items(options = {}) ⇒ Object
- .post(path, options = {}) ⇒ Object
- .put(path, options = {}) ⇒ Object
- .rate_limit ⇒ Object
- .search(keyword, options = {}) ⇒ Object
- .tag(url_name) ⇒ Object
- .tags(options = {}) ⇒ Object
- .user(url_name) ⇒ Object
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
- #me ⇒ Object
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
- #search(keyword, options = {}) ⇒ Object
- #stock!(uuid) ⇒ Object
- #stocks(options = {}) ⇒ Object
- #unstock!(uuid) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
11 12 13 |
# File 'lib/kiita/api.rb', line 11 def initialize( = {}) @token = [:token] end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/kiita/api.rb', line 9 def token @token end |
Class Method Details
.authenticate(url_name, password) ⇒ Object
39 40 41 |
# File 'lib/kiita/api.rb', line 39 def self.authenticate(url_name, password) post("/auth", url_name: url_name, password: password) end |
.delete(path, options = {}) ⇒ Object
95 96 97 |
# File 'lib/kiita/api.rb', line 95 def self.delete(path, = {}) handle_response(connection.delete(qiita_url(path), )) end |
.get(path, options = {}) ⇒ Object
83 84 85 |
# File 'lib/kiita/api.rb', line 83 def self.get(path, = {}) handle_response(connection.get(qiita_url(path), )) end |
.item(uuid) ⇒ Object
47 48 49 |
# File 'lib/kiita/api.rb', line 47 def self.item(uuid) Kiita::Post.lazy_load(uuid) end |
.items(options = {}) ⇒ Object
51 52 53 |
# File 'lib/kiita/api.rb', line 51 def self.items( = {}) Kiita::Post.all() end |
.post(path, options = {}) ⇒ Object
87 88 89 |
# File 'lib/kiita/api.rb', line 87 def self.post(path, = {}) handle_response(connection.post(qiita_url(path), )) end |
.put(path, options = {}) ⇒ Object
91 92 93 |
# File 'lib/kiita/api.rb', line 91 def self.put(path, = {}) handle_response(connection.put(qiita_url(path), )) end |
.rate_limit ⇒ Object
35 36 37 |
# File 'lib/kiita/api.rb', line 35 def self.rate_limit get("/rate_limit") end |
.search(keyword, options = {}) ⇒ Object
55 56 57 |
# File 'lib/kiita/api.rb', line 55 def self.search(keyword, = {}) Kiita::Post.search(keyword, ) end |
.tag(url_name) ⇒ Object
59 60 61 |
# File 'lib/kiita/api.rb', line 59 def self.tag(url_name) Kiita::Tag.new(url_name) end |
Instance Method Details
#delete(path, options = {}) ⇒ Object
79 80 81 |
# File 'lib/kiita/api.rb', line 79 def delete(path, = {}) self.class.delete(path_with_credentials(path), ) end |
#get(path, options = {}) ⇒ Object
67 68 69 |
# File 'lib/kiita/api.rb', line 67 def get(path, = {}) self.class.get(path_with_credentials(path), .merge!(token: token)) end |
#post(path, options = {}) ⇒ Object
71 72 73 |
# File 'lib/kiita/api.rb', line 71 def post(path, = {}) self.class.post(path_with_credentials(path), ) end |
#put(path, options = {}) ⇒ Object
75 76 77 |
# File 'lib/kiita/api.rb', line 75 def put(path, = {}) self.class.put(path_with_credentials(path), ) end |
#search(keyword, options = {}) ⇒ Object
19 20 21 |
# File 'lib/kiita/api.rb', line 19 def search(keyword, = {}) get("/search", .merge!(q: keyword)).map{|post| Kiita::Post.new(post) } end |
#stock!(uuid) ⇒ Object
27 28 29 |
# File 'lib/kiita/api.rb', line 27 def stock!(uuid) (response = put("/items/#{uuid}/stock")).nil? ? true : response end |
#stocks(options = {}) ⇒ Object
23 24 25 |
# File 'lib/kiita/api.rb', line 23 def stocks( = {}) get("/stocks", ).map{|post| Kiita::Post.new(post) } end |
#unstock!(uuid) ⇒ Object
31 32 33 |
# File 'lib/kiita/api.rb', line 31 def unstock!(uuid) (response = delete("/items/#{uuid}/stock")).nil? ? true : response end |