Class: ZenfolioAPI::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ZenfolioAPI/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Session

Create the Zenfolio Session

Parameters:

  • username (String)
  • password (String)

Author:

  • David Slone



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ZenfolioAPI/session.rb', line 15

def initialize username, password
	@username = username
	@password = password
	@auth = ZenfolioAPI::Authentication.new(username, password)

	@response = load_private_profile
	@username = @response['result']['LoginName'] if @response['result']['LoginName'] != @username

	@galleries = []
	@photos = []
	@groups = []
end

Instance Attribute Details

#galleriesObject

Returns the value of attribute galleries.



5
6
7
# File 'lib/ZenfolioAPI/session.rb', line 5

def galleries
  @galleries
end

#groupsObject

Returns the value of attribute groups.



7
8
9
# File 'lib/ZenfolioAPI/session.rb', line 7

def groups
  @groups
end

#photosObject

Returns the value of attribute photos.



6
7
8
# File 'lib/ZenfolioAPI/session.rb', line 6

def photos
  @photos
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/ZenfolioAPI/session.rb', line 8

def username
  @username
end

Instance Method Details

#api_request(method, params = nil) ⇒ Object

Performs the API request to the Zenfolio server

Author:

  • David Slone



31
32
33
34
# File 'lib/ZenfolioAPI/session.rb', line 31

def api_request method, params = nil
	connection = ZenfolioAPI::HTTP.new()
	@response = connection.POST(method, params, @auth.token)
end

#collection_add_photo(collection_id, photo_id) ⇒ Object

The CollectionAddPhoto method adds a photo reference to the specified collection.

Parameters:

  • collection_id (Integer)

    64-bit identifier of the collection to modify

  • photo_id (Integer)

    64-bit identifier of the photo to add

Raises:

Author:

  • David Slone



48
49
50
51
52
53
54
55
56
# File 'lib/ZenfolioAPI/session.rb', line 48

def collection_add_photo collection_id, photo_id
	raise ZenfolioAPI::ZenfolioAPISessionError, "Missing collection_id parameter" if collection_id.nil? || collection_id.to_i == 0
	raise ZenfolioAPI::ZenfolioAPISessionError, "Missing photo_id parameter" if photo_id.nil? || photo_id.to_i == 0

	@response = api_request 'CollectionAddPhoto', [collection_id, photo_id]
	raise ZenfolioAPI::ZenfolioAPISessionError, @response['error']['message'] if @response['result'].nil? && @response['error'].length > 0

	# TODO: Finish implementing method
end

#get_mailbox_messages(mailbox_id, posted_since = "", include_deleted = "false") ⇒ Object

The LoadMessages method loads comments or guestbook entries posted to a mailbox.

Raises:

Author:

  • David Slone



134
135
136
137
138
139
140
141
# File 'lib/ZenfolioAPI/session.rb', line 134

def get_mailbox_messages mailbox_id, posted_since = "", include_deleted = "false"
	posted_since = Date.today if posted_since.length == 0

	@response = api_request 'LoadMessages', [mailbox_id, posted_since, include_deleted]
	raise ZenfolioAPI::ZenfolioAPISessionError, @response['error']['message'] if @response['result'].nil? && @response['error'].length > 0

	
end

List images for a specific gallery

Parameters:

  • gallery_id (Integer)

    64-bit identifier of the photoset/gallery to load

  • info_level (String) (defaults to: "Full")

    Specifies which PhotoSet snapshot fields to return. This parameter is new in API version 1.4.

  • include_photos (String) (defaults to: "true")

    Specifies whether to return photoset photos. This parameter is new in API version 1.4.

Raises:

Author:

  • David Slone



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ZenfolioAPI/session.rb', line 109

def images_for_gallery gallery_id, info_level = "Full", include_photos = "true"
	@response = api_request 'LoadPhotoSet', [gallery_id, info_level, include_photos]
	raise ZenfolioAPI::ZenfolioAPISessionError, @response['error']['message'] if @response['result'].nil? && @response['error'].length > 0

	@response['result']['Photos'].each do |value|
		access_descriptor = ZenfolioAPI::Model::AccessDescriptor.new(:realm_id => value['AccessDescriptor']['RealmId'], 
			:access_type => value['AccessDescriptor']['AccessType'], :is_derived => value['AccessDescriptor']['IsDerived'], 
			:access_mask => value['AccessDescriptor']['AccessMask'], :password_hint => value['AccessDescriptor']['PasswordHint'], 
			:src_password_hint => value['AccessDescriptor']['SrcPasswordHint'])

		@photos << ZenfolioAPI::Model::Image.new(:id => value['Id'], :width => value['Width'], :height => value['Height'], :sequence => value['Sequence'], 
			:access_descriptor => access_descriptor, :owner => value['Owner'], :title => value['Title'], :mime_type => value['MimeType'], 
			:size => value['Size'], :gallery => value['Gallery'], :original_url => value['OriginalUrl'], :url_core => value['UrlCore'], 
			:url_host => value['UrlHost'], :url_token => value['UrlToken'], :page_url => value['PageUrl'], :mailbox_id => value['MailboxId'], 
			:text_cn => value['TextCn'], :flags => value['Flags'], :is_video => value['IsVideo'], :duration => value['Duration'], :caption => value['Caption'], 
			:file_name => value['FileName'], :uploaded_on => value['UploadedOn']['Value'], :taken_on => value['TakenOn']['Value'], :keywords => value['keywords'], 
			:categories => value['Categories'], :copyright => value['Copyright'], :rotation => value['Rotation'], :exif_tags => value['ExifTags'], :short_exif => value['ShortExif'])
	end

	@photos
end

#list_galleriesHash

The LoadGroupHierarchy method obtains a snapshot of the entire photoset group hierarchy of the specified user.

Returns:

  • (Hash)

    Returns a hash that contains the Galleries and Groups at the top level for a users account.

Author:

  • David Slone



62
63
64
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
92
93
94
95
96
97
98
99
100
101
# File 'lib/ZenfolioAPI/session.rb', line 62

def list_galleries
	@response = api_request 'LoadGroupHierarchy', [@username]

	@response['result']['Elements'].each do |value|
		if value['$type'] == "PhotoSet"
			@galleries << ZenfolioAPI::Model::Gallery.new(:id => value['Id'], :type => value['$type'], :caption => value['Caption'], 
				:created_on => value['CreatedOn']['Value'], :modified_on => value['ModifiedOn']['Value'], :photo_count => value['PhotoCount'],
				:image_count => value['ImageCount'], :video_count => value['VideoCount'], :photo_bytes => value['PhotoBytes'], :views => value['Views'],
				:featured_index => value['FeaturedIndex'], :is_random_title_photo => value['IsRandomTitlePhoto'], :upload_url => value['UploadUrl'],
				:video_upload_url => value['VideoUploadUrl'], :page_url => value['PageUrl'], :mailbox_id => value['MailboxId'], :text_cn => value['TextCn'], 
				:photo_list_cn => value['PhotoListCn'], :group_index => value['GroupIndex'], :title => value['Title'], :owner => value['Owner'])
		elsif value['$type'] == "Group"	
			elements = []
			value['Elements'].each do |element|
				if element['$type'] == "PhotoSet"
					elements << ZenfolioAPI::Model::Gallery.new(:id => element['Id'], :type => element['$type'], :caption => element['Caption'], 
						:created_on => element['CreatedOn']['Value'], :modified_on => element['ModifiedOn']['Value'], :photo_count => element['PhotoCount'],
						:image_count => element['ImageCount'], :video_count => element['VideoCount'], :photo_bytes => element['PhotoBytes'], :views => element['Views'],
						:featured_index => element['FeaturedIndex'], :is_random_title_photo => element['IsRandomTitlePhoto'], :upload_url => element['UploadUrl'],
						:video_upload_url => element['VideoUploadUrl'], :page_url => element['PageUrl'], :mailbox_id => element['MailboxId'], :text_cn => element['TextCn'], 
						:photo_list_cn => element['PhotoListCn'], :group_index => element['GroupIndex'], :title => element['Title'], :owner => element['Owner'])
				else
					#group_elements = load_group element['Id']
					elements << ZenfolioAPI::Model::Group.new(:id => element['Id'], :created_on => element['CreatedOn']['Value'], :modified_on => element['ModifiedOn']['Value'], 
						:page_url => element['PageUrl'], :mailbox_id => element['MailboxId'], :immediate_children_count => value['ImmediateChildrenCount'], :text_cn => element['TextCn'], 
						:caption => element['Caption'], :collection_count => value['CollectionCount'], :sub_group_count => value['SubGroupCount'], :gallery_count => value['GalleryCount'],
						:featured_index => element['FeaturedIndex'], :is_random_title_photo => element['IsRandomTitlePhoto'], :upload_url => element['UploadUrl'],
						:photo_count => value['PhotoCount'], :parent_groups => value['ParentGroups'], :title => value['Title'])
				end
			end

			@groups << ZenfolioAPI::Model::Group.new(:id => value['Id'], :created_on => value['CreatedOn']['Value'], :modified_on => value['ModifiedOn']['Value'], 
				:page_url => value['PageUrl'], :mailbox_id => value['MailboxId'], :immediate_children_count => value['ImmediateChildrenCount'], :text_cn => value['TextCn'],
				:caption => value['Caption'], :collection_count => value['CollectionCount'], :sub_group_count => value['SubGroupCount'], :gallery_count => value['GalleryCount'],
				:photo_count => value['PhotoCount'], :parent_groups => value['ParentGroups'], :elements => elements, :title => value['Title'])
		end
	end

	{:galleries => @galleries, :groups => @groups}
end

#load_group(group_id, info_level = "Full", include_children = "true") ⇒ Array

The LoadGroup method obtains a snapshot of the specified photoset group.

Parameters:

  • group_id (Integer)

    64-bit identifier of the photoset group to load

  • info_level (String) (defaults to: "Full")

    Specifies which Group snapshot fields to return. This parameter is new in API version 1.4.

  • include_children (String) (defaults to: "true")

    Indicates whether to return immediate group children. This parameter is new in API version 1.4.

Returns:

  • (Array)

    Returns an array of elements from the group. Elements can be Galleries or Groups.

Raises:

Author:

  • David Slone



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/ZenfolioAPI/session.rb', line 150

def load_group group_id, info_level = "Full", include_children = "true"
	@response = api_request 'LoadGroup', [group_id, info_level, include_children]
	raise ZenfolioAPI::ZenfolioAPISessionError, @response['error']['message'] if @response['result'].nil? && @response['error'].length > 0

	elements = []
	@response['result']['Elements'].each do |element|
		if element['$type'] == "PhotoSet"
			elements << ZenfolioAPI::Model::Gallery.new(:id => element['Id'], :type => element['$type'], :caption => element['Caption'], 
				:created_on => element['CreatedOn']['Value'], :modified_on => element['ModifiedOn']['Value'], :photo_count => element['PhotoCount'],
				:image_count => element['ImageCount'], :video_count => element['VideoCount'], :photo_bytes => element['PhotoBytes'], :views => element['Views'],
				:featured_index => element['FeaturedIndex'], :is_random_title_photo => element['IsRandomTitlePhoto'], :upload_url => element['UploadUrl'],
				:video_upload_url => element['VideoUploadUrl'], :page_url => element['PageUrl'], :mailbox_id => element['MailboxId'], :text_cn => element['TextCn'], 
				:photo_list_cn => element['PhotoListCn'], :group_index => element['GroupIndex'], :title => element['Title'], :owner => element['Owner'])
		else
			#group_elements = load_group element['Id']
			elements << ZenfolioAPI::Model::Group.new(:id => element['Id'], :created_on => element['CreatedOn']['Value'], :modified_on => element['ModifiedOn']['Value'], 
				:page_url => element['PageUrl'], :mailbox_id => element['MailboxId'], :immediate_children_count => element['ImmediateChildrenCount'], :text_cn => element['TextCn'], 
				:caption => element['Caption'], :collection_count => element['CollectionCount'], :sub_group_count => element['SubGroupCount'], :gallery_count => element['GalleryCount'],
				:featured_index => element['FeaturedIndex'], :is_random_title_photo => element['IsRandomTitlePhoto'], :upload_url => element['UploadUrl'],
				:photo_count => element['PhotoCount'], :parent_groups => element['ParentGroups'], :title => element['Title'])
		end
	end

	@group = ZenfolioAPI::Model::Group.new(:id => @response['result']['Id'], :created_on => @response['result']['CreatedOn']['Value'], :modified_on => @response['result']['ModifiedOn']['Value'], 
		:page_url => @response['result']['PageUrl'], :mailbox_id => @response['result']['MailboxId'], :immediate_children_count => @response['result']['ImmediateChildrenCount'], 
		:text_cn => @response['result']['TextCn'], :caption => @response['result']['Caption'], :collection_count => @response['result']['CollectionCount'], 
		:sub_group_count => @response['result']['SubGroupCount'], :gallery_count => @response['result']['GalleryCount'], :featured_index => @response['result']['FeaturedIndex'], 
		:is_random_title_photo => @response['result']['IsRandomTitlePhoto'], :upload_url => @response['result']['UploadUrl'], :photo_count => @response['result']['PhotoCount'], 
		:parent_groups => @response['result']['ParentGroups'], :title => @response['result']['Title'], :elements => elements)

	@group
end

#load_photo(photo_id, info_level = "Full") ⇒ Object

The LoadPhoto method obtains a snapshot of the specified photo.

Parameters:

  • photo_id (Integer)

    64-bit identifier of the photo to load.

  • info_level (String) (defaults to: "Full")

    Specifies which Photo snapshot fields to return. This parameter is new in API version 1.4.

Raises:

Author:

  • David Slone



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/ZenfolioAPI/session.rb', line 208

def load_photo photo_id, info_level = "Full"
	@response = api_request 'LoadPhoto', [photo_id, info_level]
	raise ZenfolioAPI::ZenfolioAPISessionError, @response['error']['message'] if @response['result'].nil? && @response['error'].length > 0

	value = @response['result']

	access_descriptor = ZenfolioAPI::Model::AccessDescriptor.new(:realm_id => value['AccessDescriptor']['RealmId'], 
		:access_type => value['AccessDescriptor']['AccessType'], :is_derived => value['AccessDescriptor']['IsDerived'], 
		:access_mask => value['AccessDescriptor']['AccessMask'], :password_hint => value['AccessDescriptor']['PasswordHint'], 
		:src_password_hint => value['AccessDescriptor']['SrcPasswordHint'])

	@photo = ZenfolioAPI::Model::Image.new(:id => value['Id'], :width => value['Width'], :height => value['Height'], :sequence => value['Sequence'], 
		:access_descriptor => access_descriptor, :owner => value['Owner'], :title => value['Title'], :mime_type => value['MimeType'], 
		:size => value['Size'], :gallery => value['Gallery'], :original_url => value['OriginalUrl'], :url_core => value['UrlCore'], 
		:url_host => value['UrlHost'], :url_token => value['UrlToken'], :page_url => value['PageUrl'], :mailbox_id => value['MailboxId'], 
		:text_cn => value['TextCn'], :flags => value['Flags'], :is_video => value['IsVideo'], :duration => value['Duration'], :caption => value['Caption'], 
		:file_name => value['FileName'], :uploaded_on => value['UploadedOn']['Value'], :taken_on => value['TakenOn']['Value'], :keywords => value['keywords'], 
		:categories => value['Categories'], :copyright => value['Copyright'], :rotation => value['Rotation'], :exif_tags => value['ExifTags'], :short_exif => value['ShortExif'])

	@photo
end

#load_photo_set(gallery_id, info_level = "Full", include_photos = "false") ⇒ Object

The LoadPhotoSet method obtains a snapshot of the specified photoset (gallery or collection).

Parameters:

  • gallery_id (Integer)

    64-bit identifier of the photoset/gallery to load

  • info_level (String) (defaults to: "Full")

    Specifies which PhotoSet snapshot fields to return. This parameter is new in API version 1.4.

  • include_photos (String) (defaults to: "false")

    Specifies whether to return photoset photos. This parameter is new in API version 1.4.

Raises:

Author:

  • David Slone



189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/ZenfolioAPI/session.rb', line 189

def load_photo_set gallery_id, info_level = "Full", include_photos = "false"
	@response = api_request 'LoadPhotoSet', [gallery_id, info_level, include_photos]
	raise ZenfolioAPI::ZenfolioAPISessionError, @response['error']['message'] if @response['result'].nil? && @response['error'].length > 0

	photo_set = ZenfolioAPI::Model::Gallery.new(:id => @response['result']['Id'], :type => @response['result']['$type'], :caption => @response['result']['Caption'], 
		:created_on => @response['result']['CreatedOn']['Value'], :modified_on => @response['result']['ModifiedOn']['Value'], :photo_count => @response['result']['PhotoCount'],
		:image_count => @response['result']['ImageCount'], :video_count => @response['result']['VideoCount'], :photo_bytes => @response['result']['PhotoBytes'], :views => @response['result']['Views'],
		:featured_index => @response['result']['FeaturedIndex'], :is_random_title_photo => @response['result']['IsRandomTitlePhoto'], :upload_url => @response['result']['UploadUrl'],
		:video_upload_url => @response['result']['VideoUploadUrl'], :page_url => @response['result']['PageUrl'], :mailbox_id => @response['result']['MailboxId'], :text_cn => @response['result']['TextCn'], 
		:photo_list_cn => @response['result']['PhotoListCn'], :group_index => @response['result']['GroupIndex'], :title => @response['result']['Title'], :owner => @response['result']['Owner'])

	photo_set
end

#load_private_profileObject

Author:

  • David Slone



39
40
41
# File 'lib/ZenfolioAPI/session.rb', line 39

def load_private_profile
	api_request 'LoadPrivateProfile'
end