Class: ActivityMapper::WakoopaServiceModule

Inherits:
ServiceModule show all
Defined in:
lib/activity_mapper/service_modules/wakoopa.rb

Constant Summary collapse

ACTIVITY_MAP =
{
  nil => {
    'activity.occurred_at'       => 'software/last_active_at',
    'activity.caption'           => 'software/name',
    'activity_object.native_id'  => 'software/id',
    'activity_object.title'      => 'software/name',
    'activity_object.body'       => 'category/name',
    'activity_object.url'        => 'software/complete_url',
    'media.thumbnail_url'        => 'software/complete_icon_url',
    'rating_summary.rater_count' => 'software/num_users',
    'rating_summary.view_count'  => 'software/active_seconds'
  }
}
ACCEPTED_HOSTS =
[/wakoopa\.com/]

Constants inherited from ServiceModule

ServiceModule::COMMON_DIRECTIVES

Instance Method Summary collapse

Methods inherited from ServiceModule

accepts?, all_accepted_hosts, #deep_analysis_on, detect_username, #initialize, klass_for, #shallow_analysis_on, subclasses

Constructor Details

This class inherits a constructor from ActivityMapper::ServiceModule

Instance Method Details

#aggregate_activity!(options = {}) ⇒ Object

TODO: since this is a summary, this should be done on create! and update! Need to implement recent activity here TODO use this data: software.complete_icon_url software.complete_thumb_url software.category software.num_users software.developer software.url software.active_seconds



137
138
139
140
141
142
143
144
145
146
147
148
149
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
182
183
184
# File 'lib/activity_mapper/service_modules/wakoopa.rb', line 137

def aggregate_activity!(options = {})
  # most_used_softwares = WakoopaConnector.most_used_for(username)
  # attributes = attributes_or_url.is_a?(Hash) ? attributes_or_url : {:username => username_from_url(attributes_or_url)}
  #activities = WakoopaConnector.get_all_activity_for(username)
  #activities.each { |activity,data| aggregate_for_activity(activity,data) }

  mapper = ActivityDataMapper.new(ACTIVITY_MAP)
  mapper.fetch!("http://api.wakoopa.com/#{@profile.username}/recently_used.json", 
    :format => :json, 
    :strip_callback => true
  )
  mapper.map!
  mapper.entries.each do |entry|
    next if Activity.exists?(@profile.user_id, entry)
    create_activity(entry, ActivityObjectType::SOFTWARE, ActivityVerb::RECENTLY_USED)
  end

=begin
data.each do |software|

  occurred_at = (software['software']['created_at'])

  next if Activity.exists?(self.user_id, software['software']['name'], occurred_at)

  activity            = Activity.create(
    :service_profile  => self,
    :user_id          => self.user_id,
    :native_id        => software['software']['id'].to_i,
    :activity_verb_id => ActivityVerb::RECENTLY_USED.id,
    :url              => software['software']['complete_url'],
    :occurred_at      => occurred_at # UTC OK
  )

  body = (software['software']['category'].class == NilClass) ? "" : software['software']['category']['description']

  activity.object            = ActivityObject.create(
    :title                   => software['software']['name'],
    :body                    => body,
    :url                     => activity.url,
    :native_id               => activity.native_id,
    :activity_object_type_id => ActivityObjectType::STATUS.id
  )

  activity.save
end
=end

end

#create_or_update_summary!(options = {}) ⇒ Object

Available data

team: active seconds
team: created-at
team: description
team: id
team: name
team: num-users
team: complete-url


121
122
123
124
125
126
# File 'lib/activity_mapper/service_modules/wakoopa.rb', line 121

def create_or_update_summary!(options = {})
  #softwares = WakoopaConnector.most_used_for(attributes[:username]) # Gebeurt er nog wat met softwares? Nee, niet echt :]
  # avatar not (yet) available in the API calls
  # native_user_id not (yet) available in the API calls
  @profile.update_attributes(:username => self.class.username_from_url(@profile.url))
end