Class: AboutYou::SDK::Model::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/AboutYou/Model/image.rb

Overview

This class is a represenatation of an Image model

Constant Summary collapse

MIN_WIDTH =

min width of an image

50
MIN_HEIGHT =

min height of an image

50
MAX_WIDTH =

max width of an image

1400
MAX_HEIGHT =

max height of an image

2000

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.base_urlObject

base image url



19
20
21
# File 'lib/AboutYou/Model/image.rb', line 19

def base_url
  @base_url
end

Instance Attribute Details

#additional_itemsObject

Array of additional items



22
23
24
# File 'lib/AboutYou/Model/image.rb', line 22

def additional_items
  @additional_items
end

#angleObject

Integer angle of the image



24
25
26
# File 'lib/AboutYou/Model/image.rb', line 24

def angle
  @angle
end

#backgroundObject

String background color of image



26
27
28
# File 'lib/AboutYou/Model/image.rb', line 26

def background
  @background
end

#colorObject

String color of image



28
29
30
# File 'lib/AboutYou/Model/image.rb', line 28

def color
  @color
end

#extObject

ext



30
31
32
# File 'lib/AboutYou/Model/image.rb', line 30

def ext
  @ext
end

#file_sizeObject

Integer file size



38
39
40
# File 'lib/AboutYou/Model/image.rb', line 38

def file_size
  @file_size
end

#focusObject

String focus of the image



40
41
42
# File 'lib/AboutYou/Model/image.rb', line 40

def focus
  @focus
end

#genderObject

String gender of the image



32
33
34
# File 'lib/AboutYou/Model/image.rb', line 32

def gender
  @gender
end

#hashObject

String hash of the image



34
35
36
# File 'lib/AboutYou/Model/image.rb', line 34

def hash
  @hash
end

#image_sizeObject

instance of AboutYou::SDK::Model::ImageSize



36
37
38
# File 'lib/AboutYou/Model/image.rb', line 36

def image_size
  @image_size
end

#mime_typeObject

Integer mime type of the image



42
43
44
# File 'lib/AboutYou/Model/image.rb', line 42

def mime_type
  @mime_type
end

#model_dataObject

Hash model data



44
45
46
# File 'lib/AboutYou/Model/image.rb', line 44

def model_data
  @model_data
end

#next_detail_levelObject

Integer next detail level



46
47
48
# File 'lib/AboutYou/Model/image.rb', line 46

def next_detail_level
  @next_detail_level
end

#preparationObject

String preparation



48
49
50
# File 'lib/AboutYou/Model/image.rb', line 48

def preparation
  @preparation
end

#tagsObject

Array of String tags



50
51
52
# File 'lib/AboutYou/Model/image.rb', line 50

def tags
  @tags
end

#typeObject

Integer type



52
53
54
# File 'lib/AboutYou/Model/image.rb', line 52

def type
  @type
end

#viewObject

String View



54
55
56
# File 'lib/AboutYou/Model/image.rb', line 54

def view
  @view
end

Class Method Details

.create_from_json(json_object) ⇒ Object

This method is used for creating an instance of this class by a json_object.

  • Args :

    • json_object -> the json_object received from the api

  • Returns :

    • Instance of AboutYou::SDK::Model::Image



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/AboutYou/Model/image.rb', line 65

def self.create_from_json(json_object)
  image = new

  image.additional_items  = json_object['additional_items'] ? json_object['additional_items'] : nil
  image.angle             = json_object['angle'] ? json_object['angle'] : nil
  image.background        = json_object['background'] ? json_object['background'] : nil
  image.color             = json_object['color'] ? json_object['color'] : nil
  image.ext               = json_object['ext'] ? json_object['ext'] : nil
  image.file_size         = json_object['size'] ? json_object['size'] : 0
  image.focus             = json_object['focus'] ? json_object['focus'] : nil
  image.gender            = json_object['gender'] ? json_object['gender'] : nil
  image.hash              = json_object['hash'] ? json_object['hash'] : nil
  image.mime_type         = json_object['mime'] ? json_object['mime'] : nil
  image.model_data        = json_object['model_data'] ? json_object['model_data'] : nil
  image.next_detail_level = json_object['next_detail_level'] ? json_object['next_detail_level'] : nil
  image.preparation       = json_object['preparation'] ? json_object['preparation'] : nil
  image.tags              = json_object['tags'] ? json_object['tags'] : nil
  image.type              = json_object['type'] ? json_object['type'] : nil
  image.view              = json_object['view'] ? json_object['view'] : nil

  image.image_size = ImageSize.new(
    Integer(json_object['image']['width']),
    Integer(json_object['image']['height'])
  )

  image
end

Instance Method Details

#url(width = 200, height = 200) ⇒ Object

This method is used for getting the image url for image

  • Args :

    • width -> Width of the image

    • height -> Height of the image

  • Returns :

    • String url for the image



103
104
105
106
107
108
109
# File 'lib/AboutYou/Model/image.rb', line 103

def url(width = 200, height = 200)
  width = [[width, MAX_WIDTH].min, MIN_WIDTH].max
  height = [[height, MAX_HEIGHT].min, MIN_HEIGHT].max

  self.class.base_url + '/' + hash + '?width=' + String(width) +
    '&height=' + String(height)
end