Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Instagram #1345

Closed
wants to merge 1 commit into from

3 participants

Dongri Jin Jon Ursenbach Josh Nichols
Dongri Jin

Add instagram API

Jon Ursenbach

They aren't accepting new scripts here anymore. Package your script up and publish it on NPM.

Josh Nichols

Looks like there's some name overlap, check out #1150 and hubot-scripts/packages#6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 2, 2014
  1. Dongri Jin

    Add Instagram

    dongri authored
This page is out of date. Refresh to see the latest.
Showing with 56 additions and 0 deletions.
  1. +56 −0 src/scripts/instagram.coffee
56 src/scripts/instagram.coffee
View
@@ -0,0 +1,56 @@
+# Description:
+# Messing around with the Instagram API.
+#
+# Dependencies:
+# "underscore": "1.6.0"
+#
+# Configuration:
+# HUBOT_INSTAGRAM_CLIENT_ID (http://instagram.com/developer/clients/manage/)
+#
+# Commands:
+# hubot instagram popular.
+# hubot instagram user <query>.
+
+# Author:
+# Dongri Jin
+
+INSTAGRAM_API = "https://api.instagram.com/v1"
+INSTAGRAM_CLIENT = "client_id=#{process.env.HUBOT_INSTAGRAM_CLIENT_ID}"
+
+_ = require 'underscore'
+module.exports = (robot) ->
+ robot.respond /(instagram|insta) popular/i, (msg) ->
+ robot.http("#{INSTAGRAM_API}/media/popular?#{INSTAGRAM_CLIENT}")
+ .query({})
+ .get() (err, res, body) ->
+ json = JSON.parse(body)
+ data = json.data
+ data = _.shuffle(data)
+ data = data.slice(0, 1)
+ data.forEach (d) ->
+ msg.send d.images.low_resolution.url
+
+ robot.respond /(instagram|insta) user (.*)/i, (msg) ->
+ username = msg.match[2]
+ robot.http("#{INSTAGRAM_API}/users/search?#{INSTAGRAM_CLIENT}")
+ .query({q:username})
+ .get() (err, res, body) ->
+ json = JSON.parse(body)
+ data = json.data
+ if data.length > 0
+ d = data[0]
+ id = d.id
+ robot.http("#{INSTAGRAM_API}/users/#{id}/media/recent?#{INSTAGRAM_CLIENT}")
+ .query({})
+ .get() (err, res, body) ->
+ json = JSON.parse(body)
+ if json.meta.code is 200
+ data = json.data
+ data = _.shuffle(data)
+ data = data.slice(0, 1)
+ data.forEach (d) ->
+ msg.send d.images.low_resolution.url
+ else
+ msg.send "No results for \"#{username}\""
+ else
+ msg.send "No results for \"#{username}\""
Something went wrong with that request. Please try again.