input stringlengths 109 5.2k | output stringlengths 7 509 |
|---|---|
Summarize the following code: def custom_fields
response = get "customfields"
response.map{|item| Hashie::Mash.new(item)}
end | Gets the custom fields for this list . |
Summarize the following code: def segments
response = get "segments"
response.map{|item| Hashie::Mash.new(item)}
end | Gets the segments for this list . |
Summarize the following code: def active(date="", page=1, page_size=1000, order_field="email",
order_direction="asc", include_tracking_preference=false)
paged_result_by_date("active", date, page, page_size, order_field,
order_direction, include_tracking_preference)
end | Gets the active subscribers for this list . |
Summarize the following code: def webhooks
response = get "webhooks"
response.map{|item| Hashie::Mash.new(item)}
end | Gets the webhooks for this list . |
Summarize the following code: def update(new_email_address, name, access_level, password)
options = {
:query => { :email => @email_address },
:body => {
:EmailAddress => new_email_address,
:Name => name,
:AccessLevel => access_level,
:Password => password }.to_json }
put uri_for(client_id), options
# Update @email_address, so this object can continue to be used reliably
@email_address = new_email_address
end | Updates the person details . password is optional and will only be updated if supplied |
Summarize the following code: def campaigns
response = get 'campaigns'
response.map{|item| Hashie::Mash.new(item)}
end | Gets the sent campaigns belonging to this client . |
Summarize the following code: def scheduled
response = get 'scheduled'
response.map{|item| Hashie::Mash.new(item)}
end | Gets the currently scheduled campaigns belonging to this client . |
Summarize the following code: def drafts
response = get 'drafts'
response.map{|item| Hashie::Mash.new(item)}
end | Gets the draft campaigns belonging to this client . |
Summarize the following code: def lists
response = get 'lists'
response.map{|item| Hashie::Mash.new(item)}
end | Gets the subscriber lists belonging to this client . |
Summarize the following code: def lists_for_email(email_address)
options = { :query => { :email => email_address } }
response = get 'listsforemail', options
response.map{|item| Hashie::Mash.new(item)}
end | Gets the lists across a client to which a subscriber with a particular email address belongs . email_address - A String representing the subcriber s email address |
Summarize the following code: def people
response = get "people"
response.map{|item| Hashie::Mash.new(item)}
end | Gets the people associated with this client |
Summarize the following code: def suppressionlist(page=1, page_size=1000, order_field="email",
order_direction="asc")
options = { :query => {
:page => page,
:pagesize => page_size,
:orderfield => order_field,
:orderdirection => order_direction } }
response = get 'suppressionlist', options
Hashie::Mash.new(response)
end | Gets this client s suppression list . |
Summarize the following code: def suppress(emails)
options = { :body => {
:EmailAddresses => emails.kind_of?(String) ?
[ emails ] : emails }.to_json }
post "suppress", options
end | Adds email addresses to a client s suppression list |
Summarize the following code: def templates
response = get 'templates'
response.map{|item| Hashie::Mash.new(item)}
end | Gets the templates belonging to this client . |
Summarize the following code: def set_basics(company, timezone, country)
options = { :body => {
:CompanyName => company,
:TimeZone => timezone,
:Country => country }.to_json }
put 'setbasics', options
end | Sets the basic details for this client . |
Summarize the following code: def set_payg_billing(currency, can_purchase_credits, client_pays,
markup_percentage, markup_on_delivery=0, markup_per_recipient=0,
markup_on_design_spam_test=0)
options = { :body => {
:Currency => currency,
:CanPurchaseCredits => can_purchase_credits,
:ClientPays => client_pays,
:MarkupPercentage => markup_percentage,
:MarkupOnDelivery => markup_on_delivery,
:MarkupPerRecipient => markup_per_recipient,
:MarkupOnDesignSpamTest => markup_on_design_spam_test }.to_json }
put 'setpaygbilling', options
end | Sets the PAYG billing settings for this client . |
Summarize the following code: def set_monthly_billing(currency, client_pays, markup_percentage,
monthly_scheme = nil)
options = { :body => {
:Currency => currency,
:ClientPays => client_pays,
:MarkupPercentage => markup_percentage,
:MonthlyScheme => monthly_scheme }.to_json }
put 'setmonthlybilling', options
end | Sets the monthly billing settings for this client . monthly_scheme must be nil Basic or Unlimited |
Summarize the following code: def transfer_credits(credits, can_use_my_credits_when_they_run_out)
options = { :body => {
:Credits => credits,
:CanUseMyCreditsWhenTheyRunOut => can_use_my_credits_when_they_run_out
}.to_json }
response = post 'credits', options
Hashie::Mash.new(response)
end | Transfer credits to or from this client . |
Summarize the following code: def send_preview(recipients, personalize="fallback")
options = { :body => {
:PreviewRecipients => recipients.kind_of?(String) ?
[ recipients ] : recipients,
:Personalize => personalize }.to_json }
post "sendpreview", options
end | Sends a preview of this campaign . |
Summarize the following code: def email_client_usage
response = get "emailclientusage", {}
response.map{|item| Hashie::Mash.new(item)}
end | Gets the email clients that subscribers used to open the campaign |
Summarize the following code: def opens(date="", page=1, page_size=1000, order_field="date",
order_direction="asc")
paged_result_by_date("opens", date, page, page_size, order_field,
order_direction)
end | Retrieves the opens for this campaign . |
Summarize the following code: def clicks(date="", page=1, page_size=1000, order_field="date",
order_direction="asc")
paged_result_by_date("clicks", date, page, page_size, order_field,
order_direction)
end | Retrieves the subscriber clicks for this campaign . |
Summarize the following code: def unsubscribes(date="", page=1, page_size=1000, order_field="date",
order_direction="asc")
paged_result_by_date("unsubscribes", date, page, page_size, order_field,
order_direction)
end | Retrieves the unsubscribes for this campaign . |
Summarize the following code: def spam(date="", page=1, page_size=1000, order_field="date",
order_direction="asc")
paged_result_by_date("spam", date, page, page_size, order_field,
order_direction)
end | Retrieves the spam complaints for this campaign . |
Summarize the following code: def bounces(date="", page=1, page_size=1000, order_field="date",
order_direction="asc")
paged_result_by_date("bounces", date, page, page_size, order_field,
order_direction)
end | Retrieves the bounces for this campaign . |
Summarize the following code: def update(new_email_address, name)
options = {
:query => { :email => @email_address },
:body => {
:EmailAddress => new_email_address,
:Name => name
}.to_json }
put '/admins.json', options
# Update @email_address, so this object can continue to be used reliably
@email_address = new_email_address
end | Updates the administator details . |
Summarize the following code: def flush(async=true)
loop do
@lock.synchronize do
@queue.synchronize do
@results_unprocessed += 1
end
@queue << @buffer
@buffer = []
end
if not async
LOGGER.info('Starting synchronous flush')
@queue.synchronize do
@all_processed_condition.wait_while { @results_unprocessed > 0 }
LOGGER.info('Finished synchronous flush')
end
end
break if @buffer.size < 1
end
end | Flush the buffer If async is false block until the queue is empty |
Summarize the following code: def stringify_hash_keys(hash)
new_hash = {}
hash.each do |key, value|
new_hash[key.to_s] =
if value.is_a? Hash
stringify_hash_keys value
else
value
end
end
new_hash
end | Stringify symbolized hash keys |
Summarize the following code: def slice_hash(hash, *keys)
return {} if keys.length.zero?
new_hash = {}
hash.each do |key, value|
new_hash[key] = value if keys.include? key
end
new_hash
end | Slice keys from hash |
Summarize the following code: def login(username, password)
response = request_json(
'/api/v1/login',
method: :post,
body: {
username: username,
password: password
}
)
Session.new self, Token.new(response['data'])
end | Login REST API |
Summarize the following code: def attachments
regular_attachments = mail.attachments.reject(&:inline?)
regular_attachments.collect do |attachment|
{
name: attachment.filename,
type: attachment.mime_type,
content: Base64.encode64(attachment.body.decoded)
}
end
end | Returns a Mandrill API compatible attachment hash |
Summarize the following code: def images
inline_attachments = mail.attachments.select(&:inline?)
inline_attachments.collect do |attachment|
{
name: attachment.cid,
type: attachment.mime_type,
content: Base64.encode64(attachment.body.decoded)
}
end
end | Mandrill uses a different hash for inlined image attachments |
Summarize the following code: def get_chart_data_hash(tubes)
chart_data = {}
chart_data["total_jobs_data"] = Hash.new
chart_data["buried_jobs_data"] = Hash.new
chart_data["total_jobs_data"]["items"] = Array.new
chart_data["buried_jobs_data"]["items"] = Array.new
tubes.each do |tube|
stats = tube.stats
add_chart_data_to_hash(tube, stats[:total_jobs], chart_data["total_jobs_data"]["items"])
add_chart_data_to_hash(tube, stats[:current_jobs_buried], chart_data["buried_jobs_data"]["items"])
end
chart_data
end | Return the stats data in a format for the Bluff JS UI Charts |
Summarize the following code: def guess_min_peek_range(tubes)
min = 0
tubes.each do |tube|
response = tube.peek('ready')
if response
if min == 0
min = response.id.to_i
else
min = [min, response.id.to_i].min
end
end
end
# Add some jitter in the opposite direction of 1/4 range
jitter_min = (min-(GUESS_PEEK_RANGE*0.25)).to_i
[1, jitter_min].max
end | Pick a Minimum Peek Range Based on minumum ready jobs on all tubes |
Summarize the following code: def page_venues(page_id, options={})
response = connection.get do |req|
req.url "pages/#{page_id}/venues", options
end
venues = return_error_or_body(response, response.body.response.venues)
venues = Foursquare2.filter(venues, options[:query]) if options.has_key? :query
venues
end | Get all venues for a given page . |
Summarize the following code: def managed_pages(options={})
response = connection.get do |req|
req.url "pages/managing", options
end
return_error_or_body(response, response.body.response.managing)
end | Returns a list of managed pages . |
Summarize the following code: def search_users_by_tip(options={})
name = options.delete(:name)
options[:limit] = 500
tips = search_tips(options)
user = []
tips.each do |tip|
user << tip['user'] if check_name(tip['user'], name)
end
user.uniq
end | Search for users by tip |
Summarize the following code: def user_requests(options={})
response = connection.get do |req|
req.url "users/requests", options
end
return_error_or_body(response, response.body.response.requests)
end | Get all pending friend requests for the authenticated user |
Summarize the following code: def user_checkins(options={})
response = connection.get do |req|
req.url "users/self/checkins", options
end
return_error_or_body(response, response.body.response.checkins)
end | Get checkins for the authenticated user |
Summarize the following code: def user_friends(user_id, options={})
response = connection.get do |req|
req.url "users/#{user_id}/friends", options
end
return_error_or_body(response, response.body.response.friends)
end | Get all friends for a given user . |
Summarize the following code: def user_tips(user_id, options={})
response = connection.get do |req|
req.url "users/#{user_id}/tips", options
end
tips = return_error_or_body(response, response.body.response.tips)
tips = Foursquare2.filter(tips, options[:query]) if options.has_key? :query
tips
end | Get all tips for a given user optionally filtering by text . |
Summarize the following code: def user_todos(user_id, options={})
response = connection.get do |req|
req.url "users/#{user_id}/todos", options
end
return_error_or_body(response, response.body.response.todos)
end | Get all todos for a given user . |
Summarize the following code: def user_photos(options={})
response = connection.get do |req|
req.url "users/self/photos", options
end
return_error_or_body(response, response.body.response.photos)
end | Get the photos for the authenticated user . |
Summarize the following code: def user_venue_history(options={})
response = connection.get do |req|
req.url "users/self/venuehistory", options
end
return_error_or_body(response, response.body.response.venues)
end | Get the venue history for the authenticated user . |
Summarize the following code: def user_mayorships(user_id, options={})
response = connection.get do |req|
req.url "users/#{user_id}/mayorships", options
end
return_error_or_body(response, response.body.response.mayorships)
end | Get the mayorships for a given user . |
Summarize the following code: def user_lists(user_id, options={})
response = connection.get do |req|
req.url "users/#{user_id}/lists", options
end
return_error_or_body(response, response.body.response.lists)
end | Get the lists for a given user . |
Summarize the following code: def user_friend_request(user_id, options={})
response = connection.post do |req|
req.url "users/#{user_id}/request", options
end
return_error_or_body(response, response.body.response)
end | Request friendship with a user |
Summarize the following code: def user_set_friend_pings(user_id, value)
response = connection.post do |req|
req.url "users/#{user_id}/setpings", value
end
return_error_or_body(response, response.body.response)
end | Set pings for a friend |
Summarize the following code: def tip(tip_id, options={})
response = connection.get do |req|
req.url "tips/#{tip_id}", options
end
return_error_or_body(response, response.body.response.tip)
end | Retrieve information about a tip . |
Summarize the following code: def search_tips(options={})
response = connection.get do |req|
req.url "tips/search", options
end
return_error_or_body(response, response.body.response.tips)
end | Search for tips . |
Summarize the following code: def venue_tips(venue_id, options={})
query = options.delete(:query)
response = connection.get do |req|
req.url "venues/#{venue_id}/tips", options
end
tips = return_error_or_body(response, response.body.response.tips)
tips = Foursquare2.filter(tips, query) if query
tips
end | Search for tips from a venue . |
Summarize the following code: def add_tip(options={})
response = connection.post do |req|
req.url "tips/add", options
end
return_error_or_body(response, response.body.response.tip)
end | Add a tip |
Summarize the following code: def mark_tip_todo(tip_id, options={})
response = connection.post do |req|
req.url "tips/#{tip_id}/marktodo", options
end
return_error_or_body(response, response.body.response)
end | Mark a tip todo for the authenticated user . |
Summarize the following code: def event(event_id, options={})
response = connection.get do |req|
req.url "events/#{event_id}", options
end
return_error_or_body(response, response.body.response.event)
end | Retrieve information about an event |
Summarize the following code: def campaign(campaign_id, options={})
response = connection.get do |req|
req.url "campaigns/#{campaign_id}", options
end
return_error_or_body(response, response.body.response.campaign)
end | Retrieve information about a campaign |
Summarize the following code: def connection
params = {}
params[:client_id] = @client_id if @client_id
params[:client_secret] = @client_secret if @client_secret
params[:oauth_token] = @oauth_token if @oauth_token
params[:v] = @api_version if @api_version
params[:locale] = @locale if @locale
@connection ||= Faraday::Connection.new(:url => api_url, :ssl => @ssl, :params => params, :headers => default_headers) do |builder|
@connection_middleware.each do |middleware|
builder.use *middleware
end
builder.adapter Faraday.default_adapter
end
end | Sets up the connection to be used for all requests based on options passed during initialization . |
Summarize the following code: def return_error_or_body(response, response_body)
if response.body['meta'].code == 200
response_body
else
raise Foursquare2::APIError.new(response.body['meta'], response.body['response'])
end
end | Helper method to return errors or desired response data as appropriate . |
Summarize the following code: def checkin(checkin_id, options={})
response = connection.get do |req|
req.url "checkins/#{checkin_id}", options
end
return_error_or_body(response, response.body.response.checkin)
end | Retrive information about a single checkin . |
Summarize the following code: def recent_checkins(options={})
response = connection.get do |req|
req.url "checkins/recent", options
end
return_error_or_body(response, response.body.response.recent)
end | Retrive a list of recent checkins from friends . |
Summarize the following code: def add_checkin(options={})
response = connection.post do |req|
req.url "checkins/add", options
end
return_error_or_body(response, response.body.response.checkin)
end | Checkin on behalf of the user . |
Summarize the following code: def add_checkin_comment(checkin_id, options={})
response = connection.post do |req|
req.url "checkins/#{checkin_id}/addcomment", options
end
return_error_or_body(response, response.body.response)
end | Add a comment to a checkin . |
Summarize the following code: def add_checkin_reply(checkin_id, options={})
response = connection.post do |req|
req.url "checkins/#{checkin_id}/reply", options
end
return_error_or_body(response, response.body.response.reply)
end | Add a reply to a checkin . |
Summarize the following code: def venuegroup(group_id, options={})
response = connection.get do |req|
req.url "venuegroups/#{group_id}", options
end
return_error_or_body(response, response.body.response.venueGroup)
end | Retrieve information about a venuegroup |
Summarize the following code: def add_venuegroup(options={})
response = connection.post do |req|
req.url "venuegroups/add", options
end
return_error_or_body(response, response.body.response.venueGroup)
end | Create a venue group . If the venueId parameter is specified then the endpoint will add the specified venues to the venue group . If it is not possible to add all of the specified venues to the group then creation of the venue group will fail entirely . |
Summarize the following code: def venuegroup_update(group_id, options={})
response = connection.post do |req|
req.url "venuegroups/#{group_id}/update", options
end
return_error_or_body(response, response.body.response.venueGroup)
end | Updates a venue group . At least one of the name and venueId parameters must be specified . |
Summarize the following code: def list_venuegroup(options={})
response = connection.get do |req|
req.url "venuegroups/list", options
end
return_error_or_body(response, response.body.response.venueGroups)
end | List all venue groups owned by the user . |
Summarize the following code: def special(special_id, options={})
response = connection.get do |req|
req.url "specials/#{special_id}", options
end
return_error_or_body(response, response.body.response.special)
end | Retrieve information about a special |
Summarize the following code: def search_specials(options={})
response = connection.get do |req|
req.url "specials/search", options
end
return_error_or_body(response, response.body.response.specials.items)
end | Search for specials |
Summarize the following code: def list(list_id, options={})
response = connection.get do |req|
req.url "lists/#{list_id}", options
end
return_error_or_body(response, response.body.response.list)
end | Retrieve information about a list . |
Summarize the following code: def trending_venues(ll, options={})
options[:ll] = ll
response = connection.get do |req|
req.url "venues/trending", options
end
return_error_or_body(response, response.body.response)
end | Search for trending venues |
Summarize the following code: def search_venues_by_tip(options={})
tips = search_tips(options)
venues = []
tips.each do |tip|
venues << tip['venue']
end
venues
end | Search for venues by tip |
Summarize the following code: def venue_categories(options={})
response = connection.get do |req|
req.url "venues/categories", options
end
return_error_or_body(response, response.body.response.categories)
end | Retrieve information about all venue categories . |
Summarize the following code: def venue_links(venue_id, options={})
response = connection.get do |req|
req.url "venues/#{venue_id}/links", options
end
return_error_or_body(response, response.body.response.links)
end | Retrieve links for a venue . |
Summarize the following code: def add_venue(options={})
response = connection.post do |req|
req.url "venues/add", options
end
return_error_or_body(response, response.body.response.venue)
end | Add a venue |
Summarize the following code: def mark_venue_todo(venue_id, options={})
response = connection.post do |req|
req.url "venues/#{venue_id}/marktodo", options
end
return_error_or_body(response, response.body.response)
end | Mark a venue as todo for the authenticated user |
Summarize the following code: def suggest_completion_venues(options={})
response = connection.get do |req|
req.url "venues/suggestCompletion", options
end
return_error_or_body(response, response.body.response)
end | Suggest venue completions . Returns a list of mini - venues partially matching the search term near the location . |
Summarize the following code: def venue_menus(venue_id, options={})
response = connection.get do |req|
req.url "venues/#{venue_id}/menu", options
end
return_error_or_body(response, response.body.response)
end | Retrieve menus for a venue . |
Summarize the following code: def venues_timeseries(options={})
options[:venueId] = options[:venueId].join(',') # Transforms the array into a 'comma-separated list' of ids.
response = connection.get do |req|
req.url "venues/timeseries", options
end
return_error_or_body(response, response.body.response)
end | Get daily venue stats for a list of venues over a time range . Client instance should represent an OAuth user who is the venues owner . |
Summarize the following code: def update_setting(setting, value, options={})
response = connection.post do |req|
req.url "settings/#{setting}/set", {:value => value}.merge(options)
end
return_error_or_body(response, response.body.response)
end | Update a single setting for the authenticated user . |
Summarize the following code: def photo(photo_id, options={})
response = connection.get do |req|
req.url "photos/#{photo_id}", options
end
return_error_or_body(response, response.body.response.photo)
end | Retrieve a photo |
Summarize the following code: def add_photo(options={})
response = connection.post('photos/add', options)
return_error_or_body(response, response.body.response.photo)
end | Add a photo |
Summarize the following code: def venue_photos(venue_id, options = {:group => 'venue'})
response = connection.get do |req|
req.url "venues/#{venue_id}/photos", options
end
return_error_or_body(response, response.body.response.photos)
end | Retrieve photos for a venue |
Summarize the following code: def forward(method, params = nil)
return unless @delegate && @delegate.respond_to?(method)
params.nil? ? @delegate.send(method) : @delegate.send(method, params)
end | Forward a method call to the delegate . |
Summarize the following code: def add(*items)
notify_will_change! if items.count > 0
items.each do |item|
collection.push item
end
@collection
end | Add items to the collection |
Summarize the following code: def <<(*list)
if list.count > 0
notify_will_change!
list.flatten.each { |e| collection.push(e) }
end
end | Append items to the collection |
Summarize the following code: def format_value(key, val, data_type = nil)
# if data_type wasn't passed, then get the data_type from the fields hash
data_type ||= self.fields[key]
val = format_operation(key, val, data_type)
case data_type
when :object
val = val.with_indifferent_access if val.is_a?(Hash)
when :array
# All "array" types use a collection proxy
val = val.to_a if val.is_a?(Parse::CollectionProxy) #all objects must be in array form
val = [val] unless val.is_a?(Array) #all objects must be in array form
val.compact! #remove any nil
val = Parse::CollectionProxy.new val, delegate: self, key: key
when :geopoint
val = Parse::GeoPoint.new(val) unless val.blank?
when :file
val = Parse::File.new(val) unless val.blank?
when :bytes
val = Parse::Bytes.new(val) unless val.blank?
when :integer
if val.nil? || val.respond_to?(:to_i) == false
val = nil
else
val = val.to_i
end
when :boolean
if val.nil?
val = nil
else
val = val ? true : false
end
when :string
val = val.to_s unless val.blank?
when :float
val = val.to_f unless val.blank?
when :acl
# ACL types go through a special conversion
val = ACL.typecast(val, self)
when :date
# if it respond to parse_date, then use that as the conversion.
if val.respond_to?(:parse_date) && val.is_a?(Parse::Date) == false
val = val.parse_date
# if the value is a hash, then it may be the Parse hash format for an iso date.
elsif val.is_a?(Hash) # val.respond_to?(:iso8601)
val = Parse::Date.parse(val["iso"] || val[:iso])
elsif val.is_a?(String)
# if it's a string, try parsing the date
val = Parse::Date.parse val
#elsif val.present?
# pus "[Parse::Stack] Invalid date value '#{val}' assigned to #{self.class}##{key}, it should be a Parse::Date or DateTime."
# raise ValueError, "Invalid date value '#{val}' assigned to #{self.class}##{key}, it should be a Parse::Date or DateTime."
end
when :timezone
val = Parse::TimeZone.new(val) if val.present?
else
# You can provide a specific class instead of a symbol format
if data_type.respond_to?(:typecast)
val = data_type.typecast(val)
else
warn "Property :#{key}: :#{data_type} has no valid data type"
val = val #default
end
end
val
end | this method takes an input value and transforms it to the proper local format depending on the data type that was set for a particular property key . Return the internal representation of a property value for a given data type . |
Summarize the following code: def all(constraints = {})
q = query( {limit: :max}.merge(constraints) )
if block_given?
# if we have a query, then use the Proc with it (more efficient)
return q.present? ? q.results(&Proc.new) : collection.each(&Proc.new)
end
# if no block given, get all the results
q.present? ? q.results : collection
end | You can get items within the collection relation filtered by a specific set of query constraints . |
Summarize the following code: def twin
h = self.as_json
h.delete(Parse::Model::OBJECT_ID)
h.delete(:objectId)
h.delete(:id)
self.class.new h
end | This method creates a new object of the same instance type with a copy of all the properties of the current instance . This is useful when you want to create a duplicate record . |
Summarize the following code: def save
unless saved? || @contents.nil? || @name.nil?
response = client.create_file(@name, @contents, @mime_type)
unless response.error?
result = response.result
@name = result[FIELD_NAME] || File.basename(result[FIELD_URL])
@url = result[FIELD_URL]
end
end
saved?
end | Save the file by uploading it to Parse and creating a file pointer . |
Summarize the following code: def where(constraints = nil)
return query.compile_where unless constraints.is_a?(Hash)
query.where constraints
query
end | Apply a set of constraints . |
Summarize the following code: def payload
msg = {
data: {
alert: alert,
badge: badge || "Increment"
}
}
msg[:data][:sound] = sound if sound.present?
msg[:data][:title] = title if title.present?
msg[:data].merge! @data if @data.is_a?(Hash)
if @expiration_time.present?
msg[:expiration_time] = @expiration_time.respond_to?(:iso8601) ? @expiration_time.iso8601(3) : @expiration_time
end
if @push_time.present?
msg[:push_time] = @push_time.respond_to?(:iso8601) ? @push_time.iso8601(3) : @push_time
end
if @expiration_interval.is_a?(Numeric)
msg[:expiration_interval] = @expiration_interval.to_i
end
if query.where.present?
q = @query.dup
if @channels.is_a?(Array) && @channels.empty? == false
q.where :channels.in => @channels
end
msg[:where] = q.compile_where unless q.where.empty?
elsif @channels.is_a?(Array) && @channels.empty? == false
msg[:channels] = @channels
end
msg
end | This method takes all the parameters of the instance and creates a proper hash structure required by Parse in order to process the push notification . |
Summarize the following code: def send(message = nil)
@alert = message if message.is_a?(String)
@data = message if message.is_a?(Hash)
client.push( payload.as_json )
end | helper method to send a message |
Summarize the following code: def distinct(field)
if field.nil? == false && field.respond_to?(:to_s)
# disable counting if it was enabled.
old_count_value = @count
@count = nil
compile_query = compile # temporary store
# add distinct field
compile_query[:distinct] = Query.format_field(field).to_sym
@count = old_count_value
# perform aggregation
return client.aggregate_objects(@table, compile_query.as_json, _opts ).result
else
raise ArgumentError, "Invalid field name passed to `distinct`."
end
end | Queries can be made using distinct allowing you find unique values for a specified field . For this to be performant please remember to index your database . |
Summarize the following code: def fetch!(compiled_query)
response = client.find_objects(@table, compiled_query.as_json, _opts )
if response.error?
puts "[ParseQuery] #{response.error}"
end
response
end | Performs the fetch request for the query . |
Summarize the following code: def decode(list)
list.map { |m| Parse::Object.build(m, @table) }.compact
end | Builds objects based on the set of Parse JSON hashes in an array . |
Summarize the following code: def compile(encode: true, includeClassName: false)
run_callbacks :prepare do
q = {} #query
q[:limit] = @limit if @limit.is_a?(Numeric) && @limit > 0
q[:skip] = @skip if @skip > 0
q[:include] = @includes.join(',') unless @includes.empty?
q[:keys] = @keys.join(',') unless @keys.empty?
q[:order] = @order.join(',') unless @order.empty?
unless @where.empty?
q[:where] = Parse::Query.compile_where(@where)
q[:where] = q[:where].to_json if encode
end
if @count && @count > 0
# if count is requested
q[:limit] = 0
q[:count] = 1
end
if includeClassName
q[:className] = @table
end
q
end
end | Complies the query and runs all prepare callbacks . |
Summarize the following code: def get(uri, query = nil, headers = {})
request :get, uri, query: query, headers: headers
end | Send a GET request . |
Summarize the following code: def post(uri, body = nil, headers = {} )
request :post, uri, body: body, headers: headers
end | Send a POST request . |
Summarize the following code: def put(uri, body = nil, headers = {})
request :put, uri, body: body, headers: headers
end | Send a PUT request . |
Summarize the following code: def delete(uri, body = nil, headers = {})
request :delete, uri, body: body, headers: headers
end | Send a DELETE request . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.