Class: Cyby::Kintone::App
- Inherits:
-
Object
- Object
- Cyby::Kintone::App
- Defined in:
- lib/cyby/kintone/app.rb
Constant Summary collapse
- LIMIT =
100
Instance Method Summary collapse
- #all ⇒ Object
- #asc(field) ⇒ Object
- #delete(record) ⇒ Object
- #desc(field) ⇒ Object
- #find(params) ⇒ Object
- #find_per_page(params, page) ⇒ Object
- #id ⇒ Object
-
#initialize(id) ⇒ App
constructor
A new instance of App.
- #inspect ⇒ Object
- #new_record ⇒ Object
- #relation ⇒ Object
- #save(record) ⇒ Object
- #select(*fields) ⇒ Object
- #where(cond, *params) ⇒ Object
Constructor Details
Instance Method Details
#all ⇒ Object
65 66 67 |
# File 'lib/cyby/kintone/app.rb', line 65 def all relation.all end |
#asc(field) ⇒ Object
73 74 75 |
# File 'lib/cyby/kintone/app.rb', line 73 def asc(field) relation.asc(field) end |
#delete(record) ⇒ Object
51 52 53 54 55 |
# File 'lib/cyby/kintone/app.rb', line 51 def delete(record) json = { ids: [record["$id"]] } @api.delete("/records.json", json) true end |
#desc(field) ⇒ Object
77 78 79 |
# File 'lib/cyby/kintone/app.rb', line 77 def desc(field) relation.desc(field) end |
#find(params) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cyby/kintone/app.rb', line 10 def find(params) result = [] page = 0 begin records = find_per_page(params, page) result.concat(records) page += 1 end while records.count == LIMIT result end |
#find_per_page(params, page) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cyby/kintone/app.rb', line 21 def find_per_page(params, page) params_per_page = params.dup queries = [params[:query]] if page > 0 queries << "offset #{LIMIT * page}" end params_per_page[:query] = queries.join(" ") response = @api.get('/records.json', params_per_page) response['records'].map do |record| Record.new(self, record) end end |
#id ⇒ Object
85 86 87 |
# File 'lib/cyby/kintone/app.rb', line 85 def id @api.app end |
#inspect ⇒ Object
89 90 91 |
# File 'lib/cyby/kintone/app.rb', line 89 def inspect { id: id }.inspect end |
#new_record ⇒ Object
57 58 59 |
# File 'lib/cyby/kintone/app.rb', line 57 def new_record Record.new(self) end |
#relation ⇒ Object
61 62 63 |
# File 'lib/cyby/kintone/app.rb', line 61 def relation Relation.new(self) end |
#save(record) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cyby/kintone/app.rb', line 34 def save(record) if record.changed? json = record.to_json_for_save if json[:id] resp = @api.put("/record.json", json) else resp = @api.post("/record.json", json) record["$id"] = resp["id"] end record["$revision"] = resp["revision"] record.unchanged true else false end end |
#select(*fields) ⇒ Object
81 82 83 |
# File 'lib/cyby/kintone/app.rb', line 81 def select(*fields) relation.select(*fields) end |
#where(cond, *params) ⇒ Object
69 70 71 |
# File 'lib/cyby/kintone/app.rb', line 69 def where(cond, *params) relation.where(cond, *params) end |