-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,51 @@ | ||
require_relative '../data/collection' | ||
require_relative 'transactor' | ||
|
||
module Emojidex | ||
module Service | ||
# a modified collection class for collections tied to the emojidex service | ||
class Collection < Emojidex::Data::Collection | ||
attr_reader :endpoint, :page | ||
attr_reader :endpoint, :page, :limit, :detailed | ||
@username | ||
@token | ||
|
||
def initialize(opts = {}) | ||
@emoji = {} | ||
@emoji = opts[:emoji] || {} | ||
|
||
@page = opts[:page] || 1 | ||
@username = opts[:username] || nil | ||
@token = opts[:token] || nil | ||
|
||
if (opts.key? :endpoint) | ||
@endpoint = opts.endpoint; | ||
@emoji = Transactor.get(endpoint, opts) | ||
end | ||
@endpoint = opts[:endpoint] || 'emoji' | ||
@page = opts[:page] || 0 | ||
@limit = opts[:limit] || 50 | ||
@detailed = opts[:detailed] || false | ||
|
||
more() | ||
@emoji | ||
end | ||
|
||
def more() | ||
@page += 1 | ||
|
||
opts = {page: @page, limit: @limit, detailed: @detailed} | ||
opts[:username] = @username unless @username.nil? | ||
opts[:auth_token] = @token unless @token.nil? | ||
|
||
page_moji = Emojidex::Service::Transactor.get(@endpoint, opts) | ||
|
||
if page_moji.is_a? Hash | ||
if !page_moji.key? :emoji | ||
@page -= 1 #reset page beacuse we failed | ||
return {} | ||
end | ||
|
||
add_emoji(page_moji[:emoji]) | ||
return page_moji[:emoji] | ||
end | ||
puts "ARRAY #{page_moji}" | ||
add_emoji(page_moji) | ||
return page_moji | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters