Class: Emojidex::Service::Collection

Inherits:
Data::Collection show all
Defined in:
lib/emojidex/service/collection.rb

Overview

A modified collection class for collections tied to the emojidex service

Instance Attribute Summary collapse

Attributes inherited from Data::Collection

#categories, #emoji, #r18, #raster_source_path, #source_path, #vector_source_path

Attributes included from Data::CollectionMojiData

#moji_code_index, #moji_code_string

Attributes included from Data::CollectionCache

#cache_path, #download_queue, #download_threads, #formats, #sizes

Instance Method Summary collapse

Methods inherited from Data::Collection

#add_emoji, #category, #category?, #collect, #each, #emojis, #find_by_code, #find_by_code_ja, #find_by_moji, #find_by_unicode, #load_local_collection, #map, #remove_emoji, #search, #select

Methods included from Data::CollectionMojiData

#condense_moji_code_data

Methods included from Data::CollectionAssetInformation

#generate_checksums, #generate_paths, #get_checksums, #get_combo_checksums, #get_combo_paths, #get_paths, #get_paths?

Methods included from Data::CollectionCache

#cache, #cache!, #cache_index, #load_cache, #setup_cache, #write_index

Constructor Details

#initialize(opts = {}) ⇒ Collection

Returns a new instance of Collection.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/emojidex/service/collection.rb', line 11

def initialize(opts = {})
  @opts = opts

  @status = ''

  @auto_cache = @opts[:auto_cache] || true
  @opts.delete(:auto_cache)

  @formats = @opts[:formats] || Emojidex::Defaults.selected_formats
  @opts.delete(:formats)

  @sizes = @opts[:sizes] || Emojidex::Defaults.selected_sizes
  @opts.delete(:sizes)

  auto_init = @opts[:auto_init] || true
  @opts.delete(:auto_init)

  _init_emoji
  
  _init_endpoint
  _init_cache

  more if auto_init

  @emoji
end

Instance Attribute Details

#auto_cacheObject (readonly)

Returns the value of attribute auto_cache.



9
10
11
# File 'lib/emojidex/service/collection.rb', line 9

def auto_cache
  @auto_cache
end

#detailedObject (readonly)

Returns the value of attribute detailed.



9
10
11
# File 'lib/emojidex/service/collection.rb', line 9

def detailed
  @detailed
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



9
10
11
# File 'lib/emojidex/service/collection.rb', line 9

def endpoint
  @endpoint
end

#limitObject (readonly)

Returns the value of attribute limit.



9
10
11
# File 'lib/emojidex/service/collection.rb', line 9

def limit
  @limit
end

#pageObject (readonly)

Returns the value of attribute page.



9
10
11
# File 'lib/emojidex/service/collection.rb', line 9

def page
  @page
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/emojidex/service/collection.rb', line 9

def status
  @status
end

Instance Method Details

#moreObject

Get the next page worth of emoji and add them to the collection



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/emojidex/service/collection.rb', line 39

def more
  @page += 1

  opts = { page: @page, limit: @limit, detailed: @detailed }
  opts[:username] = @username unless @username.nil? || @username == ''
  opts[:auth_token] = @auth_token unless @auth_token.nil? || @auth_token == ''
  opts.merge! @opts

  begin
    moji_page = Emojidex::Service::Transactor.get(@endpoint, opts)
  rescue Error::Unauthorized => e
    @status = e.message
    return {}
  rescue Error::PaymentRequired => e
    @status = e.message
    return {}
  end

  _process_moji_page(moji_page)
  
  cache! if @auto_cache

  moji_page
end