Class: EdoolsSdk::Product
- Inherits:
-
EdoolsBase
- Object
- EdoolsBase
- EdoolsSdk::Product
- Defined in:
- lib/edools_sdk/product.rb
Overview
Product class
Constant Summary collapse
- PRODUCT_URL_WITHOUT_SCHOOL =
'https://core.myedools.info/api/school_products'
Instance Attribute Summary collapse
-
#allowed_emails ⇒ Object
Returns the value of attribute allowed_emails.
-
#available_time_length ⇒ Object
Returns the value of attribute available_time_length.
-
#available_time_type ⇒ Object
Returns the value of attribute available_time_type.
-
#available_time_unit ⇒ Object
Returns the value of attribute available_time_unit.
-
#category_ids ⇒ Object
Returns the value of attribute category_ids.
-
#certification ⇒ Object
Returns the value of attribute certification.
-
#certification_min_progress ⇒ Object
Returns the value of attribute certification_min_progress.
-
#class_teacher_ids ⇒ Object
Returns the value of attribute class_teacher_ids.
-
#classes_auto_generation ⇒ Object
Returns the value of attribute classes_auto_generation.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#expire_date ⇒ Object
Returns the value of attribute expire_date.
-
#gallery_media_ids ⇒ Object
Returns the value of attribute gallery_media_ids.
-
#hidden ⇒ Object
Returns the value of attribute hidden.
-
#id ⇒ Object
Returns the value of attribute id.
-
#library_resource_id ⇒ Object
Returns the value of attribute library_resource_id.
-
#logo ⇒ Object
Returns the value of attribute logo.
-
#max_attendance_length ⇒ Object
Returns the value of attribute max_attendance_length.
-
#max_attendance_type ⇒ Object
Returns the value of attribute max_attendance_type.
-
#meta_description ⇒ Object
Returns the value of attribute meta_description.
-
#meta_keys ⇒ Object
Returns the value of attribute meta_keys.
-
#meta_title ⇒ Object
Returns the value of attribute meta_title.
-
#published ⇒ Object
Returns the value of attribute published.
-
#restricted ⇒ Object
Returns the value of attribute restricted.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#video_description ⇒ Object
Returns the value of attribute video_description.
-
#video_title ⇒ Object
Returns the value of attribute video_title.
-
#video_url ⇒ Object
Returns the value of attribute video_url.
Class Method Summary collapse
-
.all ⇒ Object
Get all products.
-
.all! ⇒ Object
Get all products, if anything goes wrong an exception will be raised.
-
.create(school_id, props) ⇒ Object
Create a product.
-
.create!(school_id, props) ⇒ Object
Create a product, if anything goes wrong an exception will be raised.
-
.parse_json(props) ⇒ Object
Parse json to Product object.
Instance Method Summary collapse
-
#initialize ⇒ Product
constructor
A new instance of Product.
-
#save(school_id) ⇒ Object
Save a product.
-
#save!(school_id) ⇒ Object
Save a product, if anything goes wrong an exception will be raised.
Methods inherited from EdoolsBase
Constructor Details
#initialize ⇒ Product
Returns a new instance of Product.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/edools_sdk/product.rb', line 41 def initialize @id = nil @title = nil @description = nil @subtitle = nil @logo = nil @video_url = nil @video_title = nil @video_description = nil @published = nil @hidden = nil @restricted = nil @certification = nil @classes_auto_generation = nil @certification_min_progress = nil @meta_title = nil @meta_description = nil @meta_keys = nil @available_time_type = nil @available_time_length = nil @available_time_unit = nil @expire_date = nil @library_resource_id = nil @max_attendance_type = nil @max_attendance_length = nil @allowed_emails = nil @class_teacher_ids = nil @category_ids = nil @gallery_media_ids = nil @created_at = nil @updated_at = nil end |
Instance Attribute Details
#allowed_emails ⇒ Object
Returns the value of attribute allowed_emails.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def allowed_emails @allowed_emails end |
#available_time_length ⇒ Object
Returns the value of attribute available_time_length.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def available_time_length @available_time_length end |
#available_time_type ⇒ Object
Returns the value of attribute available_time_type.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def available_time_type @available_time_type end |
#available_time_unit ⇒ Object
Returns the value of attribute available_time_unit.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def available_time_unit @available_time_unit end |
#category_ids ⇒ Object
Returns the value of attribute category_ids.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def category_ids @category_ids end |
#certification ⇒ Object
Returns the value of attribute certification.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def certification @certification end |
#certification_min_progress ⇒ Object
Returns the value of attribute certification_min_progress.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def certification_min_progress @certification_min_progress end |
#class_teacher_ids ⇒ Object
Returns the value of attribute class_teacher_ids.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def class_teacher_ids @class_teacher_ids end |
#classes_auto_generation ⇒ Object
Returns the value of attribute classes_auto_generation.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def classes_auto_generation @classes_auto_generation end |
#created_at ⇒ Object
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def description @description end |
#expire_date ⇒ Object
Returns the value of attribute expire_date.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def expire_date @expire_date end |
#gallery_media_ids ⇒ Object
Returns the value of attribute gallery_media_ids.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def gallery_media_ids @gallery_media_ids end |
#hidden ⇒ Object
Returns the value of attribute hidden.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def hidden @hidden end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def id @id end |
#library_resource_id ⇒ Object
Returns the value of attribute library_resource_id.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def library_resource_id @library_resource_id end |
#logo ⇒ Object
Returns the value of attribute logo.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def logo @logo end |
#max_attendance_length ⇒ Object
Returns the value of attribute max_attendance_length.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def max_attendance_length @max_attendance_length end |
#max_attendance_type ⇒ Object
Returns the value of attribute max_attendance_type.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def max_attendance_type @max_attendance_type end |
#meta_description ⇒ Object
Returns the value of attribute meta_description.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def @meta_description end |
#meta_keys ⇒ Object
Returns the value of attribute meta_keys.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def @meta_keys end |
#meta_title ⇒ Object
Returns the value of attribute meta_title.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def @meta_title end |
#published ⇒ Object
Returns the value of attribute published.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def published @published end |
#restricted ⇒ Object
Returns the value of attribute restricted.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def restricted @restricted end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def subtitle @subtitle end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def title @title end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def updated_at @updated_at end |
#video_description ⇒ Object
Returns the value of attribute video_description.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def video_description @video_description end |
#video_title ⇒ Object
Returns the value of attribute video_title.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def video_title @video_title end |
#video_url ⇒ Object
Returns the value of attribute video_url.
4 5 6 |
# File 'lib/edools_sdk/product.rb', line 4 def video_url @video_url end |
Class Method Details
.all ⇒ Object
Get all products
Example:
>> Product.all!
=> [#<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>]
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/edools_sdk/product.rb', line 139 def self.all response = HTTP .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"") .get(PRODUCT_URL_WITHOUT_SCHOOL) return response if response.status >= 400 && response.status < 600 body = response.parse(:json) body['school_products'].map { |c| Product.parse_json(c) } end |
.all! ⇒ Object
Get all products, if anything goes wrong an exception will be raised
Example:
>> Product.all!
=> [#<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>]
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/edools_sdk/product.rb', line 122 def self.all! response = HTTP .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"") .get(PRODUCT_URL_WITHOUT_SCHOOL) raise "invalid status code #{response.status}" if response.status >= 400 && response.status < 600 body = response.parse(:json) body['school_products'].map { |c| Product.parse_json(c) } end |
.create(school_id, props) ⇒ Object
Create a product
Example:
>> Product.create(222, "title" => "test")
=> #<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/edools_sdk/product.rb', line 215 def self.create(school_id, props) response = HTTP .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"") .post("#{PRODUCT_URL}#{school_id}/school_products", :json => props) return response if response.status != 201 body = response.parse(:json) Product.parse_json(body) end |
.create!(school_id, props) ⇒ Object
Create a product, if anything goes wrong an exception will be raised
Example:
>> Product.create!(222, "title" => "test")
=> #<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/edools_sdk/product.rb', line 198 def self.create!(school_id, props) response = HTTP .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"") .post("#{PRODUCT_URL}#{school_id}/school_products", :json => props) raise "invalid status code #{response.status}" if response.status != 201 body = response.parse(:json) Product.parse_json(body) end |
.parse_json(props) ⇒ Object
Parse json to Product object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/edools_sdk/product.rb', line 75 def self.parse_json(props) product = Product.new product.id = props['id'] product.title = props['title'] product.description = props['description'] product.subtitle = props['subtitle'] product.logo = props['logo'] product.video_url = props['video_url'] product.video_title = props['video_title'] product.video_description = props['video_description'] product.published = props['published'] product.hidden = props['hidden'] product.restricted = props['restricted'] product.certification = props['certification'] product.classes_auto_generation = props['classes_auto_generation'] product.certification_min_progress = props['certification_min_progress'] product. = props['meta_title'] product. = props['meta_description'] product. = props['meta_keys'] product.available_time_type = props['available_time_type'] product.available_time_length = props['available_time_length'] product.available_time_unit = props['available_time_unit'] product.expire_date = props['expire_date'] product.library_resource_id = props['library_resource_id'] product.max_attendance_type = props['max_attendance_type'] product.max_attendance_length = props['max_attendance_length'] product.allowed_emails = props['allowed_emails'] product.class_teacher_ids = props['class_teacher_ids'] product.category_ids = props['category_ids'] product.gallery_media_ids = props['gallery_media_ids'] unless props['created_at'].nil? product.created_at = Date.parse(props['created_at']) end unless props['updated_at'].nil? product.updated_at = Date.parse(props['updated_at']) end product end |
Instance Method Details
#save(school_id) ⇒ Object
Save a product
Example:
>> product_instance.save(222)
=> #<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/edools_sdk/product.rb', line 177 def save(school_id) response = HTTP .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"") .post("#{PRODUCT_URL}#{school_id}/school_products", :json => self.to_h) return response if response.status != 201 body = response.parse(:json) product_saved = Product.parse_json(body) change_values(product_saved) product_saved end |
#save!(school_id) ⇒ Object
Save a product, if anything goes wrong an exception will be raised
Example:
>> product_instance.save(222)!
=> #<EdoolsSdk::Product:0x00000002bc4a88 @id=22395, @title="test product 1", @description=nil, @subtitle=nil, @logo=nil, @video_url=nil, @video_title=nil, @video_description=nil, @published=false, @hidden=false, @restricted=false, @certification=false, @classes_auto_generation=false, @certification_min_progress=nil, @meta_title=nil, @meta_description=nil, @meta_keys=nil, @available_time_type="indeterminate", @available_time_length=nil, @available_time_unit=nil, @expire_date=nil, @library_resource_id=nil, @max_attendance_type="indeterminate", @max_attendance_length=nil, @allowed_emails=[], @class_teacher_ids=nil, @category_ids=nil, @gallery_media_ids=nil, @created_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>, @updated_at=#<Date: 2017-09-25 ((2458022j,0s,0n),+0s,2299161j)>>
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/edools_sdk/product.rb', line 156 def save!(school_id) response = HTTP .headers('Authorization' => "Token token=\"#{ENV['edools_token']}\"") .post("#{PRODUCT_URL}#{school_id}/school_products", :json => self.to_h) raise "invalid status code #{response.status}" if response.status != 201 body = response.parse(:json) product_saved = Product.parse_json(body) change_values(product_saved) product_saved end |