Class: MoxiworksPlatform::Gallery

Inherits:
Resource
  • Object
show all
Defined in:
lib/moxiworks_platform/gallery.rb

Overview

Moxi Works Platform Gallery

Instance Attribute Summary collapse

Attributes inherited from Resource

#headers

Class Method Summary collapse

Methods inherited from Resource

accept_header, attr_accessor, attributes, #attributes, auth_header, check_for_error_in_response, content_type_header, #float_attrs, headers, #init_attrs_from_hash, #initialize, #int_attrs, #method_missing, #numeric_attrs, #numeric_value_for, send_request, #to_hash, underscore, underscore_array, underscore_attribute_names, underscore_hash, user_agent_header

Constructor Details

This class inherits a constructor from MoxiworksPlatform::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MoxiworksPlatform::Resource

Instance Attribute Details

Returns array of image Hashes in the format

thumb_url: [String] url to thumbail size image (smallest),
small_url: [String] url to small size image (small),
full_url: [String] url to full size image (medium),
gallery_url: [String] url to gallery size image (large),
raw_url: [String] url to raw image (largest)
title: [String] human readable title of image
is_main_listing_image: [Boolean] whether the image is the main image for the listing
caption: [String] human readable caption for the image
description: [String] human readable description of the image
width: [Integer] width of the raw image
height: [Integer] height of the raw image
mime_type: [String] MIME or media type of the image

.

Returns:

  • (Array)

    array of image Hashes in the format

    thumb_url: [String] url to thumbail size image (smallest),
    small_url: [String] url to small size image (small),
    full_url: [String] url to full size image (medium),
    gallery_url: [String] url to gallery size image (large),
    raw_url: [String] url to raw image (largest)
    title: [String] human readable title of image
    is_main_listing_image: [Boolean] whether the image is the main image for the listing
    caption: [String] human readable caption for the image
    description: [String] human readable description of the image
    width: [Integer] width of the raw image
    height: [Integer] height of the raw image
    mime_type: [String] MIME or media type of the image
    



34
35
36
# File 'lib/moxiworks_platform/gallery.rb', line 34

def gallery_images
  @gallery_images
end

#list_office_aorString

Returns MLS the listing is listed with.

Returns:

  • (String)

    MLS the listing is listed with



8
9
10
# File 'lib/moxiworks_platform/gallery.rb', line 8

def list_office_aor
  @list_office_aor
end

#listing_idString

Returns the mls number associated with the listing.

Returns:

  • (String)

    the mls number associated with the listing



13
14
15
# File 'lib/moxiworks_platform/gallery.rb', line 13

def listing_id
  @listing_id
end

#listing_imagesArray

Returns array of image Hashes in the format

thumb_url: [String] url to thumbail size image (smallest),
small_url: [String] url to small size image (small),
full_url: [String] url to full size image (medium),
gallery_url: [String] url to gallery size image (large),
raw_url: [String] url to raw image (largest)
title: [String] human readable title of image
is_main_listing_image: [Boolean] whether the image is the main image for the listing
caption: [String] human readable caption for the image
description: [String] human readable description of the image
width: [Integer] width of the raw image
height: [Integer] height of the raw image
mime_type: [String] MIME or media type of the image

.

Returns:

  • (Array)

    array of image Hashes in the format

    thumb_url: [String] url to thumbail size image (smallest),
    small_url: [String] url to small size image (small),
    full_url: [String] url to full size image (medium),
    gallery_url: [String] url to gallery size image (large),
    raw_url: [String] url to raw image (largest)
    title: [String] human readable title of image
    is_main_listing_image: [Boolean] whether the image is the main image for the listing
    caption: [String] human readable caption for the image
    description: [String] human readable description of the image
    width: [Integer] width of the raw image
    height: [Integer] height of the raw image
    mime_type: [String] MIME or media type of the image
    



34
# File 'lib/moxiworks_platform/gallery.rb', line 34

attr_accessor :gallery_images

Class Method Details

.find(opts = {}) ⇒ Hash

Search For Galleries in Moxi Works Platform

Examples:

results = MoxiworksPlatform::Gallery.search(
moxi_works_company_id: 'the_company',
moxi_works_agent_id: 'abc123'
)
MoxiworksPlatform::Gallery.search(
   moxi_works_company_id: 'the_company',
     moxi_works_agent_id: 'abc123'
    agent_uuid: 'abc123') { |galleries| puts galleries.count }

Parameters:

  • opts (Hash) (defaults to: {})

    named parameter Hash

Options Hash (opts):

  • :moxi_works_company_id (String)

    REQUIRED The Moxi Works Company ID For the search (use Company.search to determine available moxi_works_company_id)

  • :moxi_works_agent_id (String)

    The Moxi Works Agent ID For the search (use Agent.search to determine available moxi_works_agent_id) – only agent_uuid or moxi_works_agent_id are needed when searching for galleries by agent

  • :agent_uuid (String)

    The Agent UUID For the search (use Agent.search to determine available agent_uuid) – only agent_uuid or moxi_works_agent_id are needed when searching for galleries by agent

    optional Search parameters

Returns:

  • (Hash)

    with the format:

    last_page: [Boolean],
    galleries:  [Array] containing MoxiworkPlatform::Gallery objects
    

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren't included



74
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
# File 'lib/moxiworks_platform/gallery.rb', line 74

def self.find(opts={})
  required_opts = [:moxi_works_company_id]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  agent_identifier = opts[:agent_uuid] unless(opts[:agent_uuid].nil? or opts[:agent_uuid].empty?)
  agent_identifier ||= opts[:moxi_works_agent_id] unless(opts[:moxi_works_agent_id].nil? or opts[:moxi_works_agent_id].empty?)
  raise ::MoxiworksPlatform::Exception::ArgumentError, "#agent_uuid or moxi_works_agent_id required" if
      agent_identifier.nil?

  url = "#{MoxiworksPlatform::Config.url}/api/galleries/#{agent_identifier}"

  results = MoxiResponseArray.new()
  json = {'galleries': []}
  RestClient::Request.execute(method: :get,
                              url: url,
                              payload: opts, headers: self.headers) do |response|
    puts response if MoxiworksPlatform::Config.debug
    results.headers = response.headers
    self.check_for_error_in_response(response)
    json = JSON.parse(response)
    json = self.underscore_attribute_names json

    results.page_number = 1
    results.total_pages = 1

    json['galleries'].each do |r|
      results << MoxiworksPlatform::Gallery.new(r) unless r.nil? or r.empty?
    end
    json['galleries'] = results
  end
  if block_given?
    yield(json['galleries'])
  end
  json
end