clj-instagram.requests

Pure functions for creating and transforming request maps for accessing Instagram API.

Returned request maps are compatible with clj-http library (https://github.com/dakrone/clj-http) but should be usable
with any HTTP client library with minor modifications. The following keys/values are used:

  :method       - HTTP method; :get, :post or :delete
  :url          - URL (string)
  :query-params - map of query params with keyword keys
                  (optional, applicable for GET and DELETE requests)
  :form-params  - map of form params with keyword keys
                  (optional, applicable for POST requests)


For more details about the API refer to official documentation:

* Authentication: https://www.instagram.com/developer/authentication/
* Endpoints: https://www.instagram.com/developer/endpoints/
* Subscriptions: https://www.instagram.com/developer/subscriptions/

authenticate

(authenticate req access-token)
Adds access token to the given request. Depending on the request method, access token is added either to query params
or form params.

create-comment

(create-comment media-id text)
Create a comment on a media object with the following rules:

* The total length of the comment cannot exceed 300 characters
* The comment cannot contain more than 4 hashtags
* The comment cannot contain more than 1 URL
* The comment cannot consist of all capital letters

Parameters:
  media-id - media id
  text     - comment text

create-subscription

(create-subscription client-id client-secret object aspect verify-token callback-url)
Create subscription to given aspect of the given object.

Simultaneously submits a GET request to the provided callback URL to verify its existence with the following
parameters:

* hub.mode         - this will be set to "subscribe"
* hub.challenge    - this will be set to a random string that your callback URL will need to echo back in order to
                     verify you'd like to subscribe
* hub.verify_token - this will be set to whatever verify token passed in with the subscription request,
                     it's helpful to use this to differentiate between multiple subscription requests

In order to verify the subscription, your server must respond to the GET request with the hub.challenge parameter
only.

When new data arrives, the given callback URL will receive a POST request with a payload containing the updates.

Parameters:
  client-id     - client id
  client-secret - client secret
  object        - the object to subscribe to (e.g. 'user')
  aspect        - the aspect of the object to subscribe to (e.g. 'media')
  verify-token  - verify token to use in the Pubsubhubub challenge flow
  callback-url  - callback URL (must support both GET and POST)

delete-comment

(delete-comment media-id comment-id)
Remove a comment either on the authenticated user's media object or authored by the authenticated user.

Parameters:
  media-id   - media id
  comment-id - comment id

delete-subscription

(delete-subscription client-id client-secret {:keys [object id]})
Delete subscription either by object type or subscription ID. All subscriptions can be deleted by using value "all"
as an object type.

Parameters:
  client-id     - client id
  client-secret - client secret
  object        - object type or "all" (optional, either object type or id must be given)
  id            - subscription id (optional, either object type or id must be given)

get-comments

(get-comments media-id)
Get a list of recent comments on a media object.

get-followed-by

(get-followed-by)
Get the list of users this user is followed by.

get-follows

(get-follows)
Get the list of users this user follows.

get-liked-media

(get-liked-media)(get-liked-media {:keys [count max-like-id]})
Get the list of recent media liked by the owner of the access token.

Parameters:
  count       - count of media to return (optional)
  max-like-id - return media liked before this id (optional)

get-likes

(get-likes media-id)
Get a list of users who have liked this media.

get-location

(get-location location-id)
Get information about a location.

get-media-by-id

(get-media-by-id media-id)
Get information about a media object. Use the :type field to differentiate between image and video media in the
response. You will also receive the :user_has_liked field which tells you whether the owner of the access token has
liked this media.

get-media-by-shortcode

(get-media-by-shortcode shortcode)
Get information about a media object. Use the :type field to differentiate between image and video media in the
response. You will also receive the :user_has_liked field which tells you whether the owner of the access token has
liked this media. A media object's shortcode can be found in its shortlink URL. An example shortlink is
http://instagram.com/p/tsxp1hhQTG/. Its corresponding shortcode is tsxp1hhQTG.

get-recent-media-by-me

(get-recent-media-by-me)(get-recent-media-by-me {:keys [count min-id max-id], :as optional-params})
Get the most recent media published by the owner of the access token.

Parameters:
  count   - count of media to return (optional)
  min-id  - Return media later than this min id (optional)
  max-id  - Return media earlier than this max id (optional)

get-recent-media-by-user

(get-recent-media-by-user user-id)(get-recent-media-by-user user-id {:keys [count min-id max-id]})
Get the most recent media published by a user.

Parameters:
  user-id - user id
  count   - count of media to return (optional)
  min-id  - return media later than this min id (optional)
  max-id  - return media earlier than this max id (optional)

get-recent-media-from-location

(get-recent-media-from-location location-id)(get-recent-media-from-location location-id {:keys [min-id max-id]})
Get a list of recent media objects from a given location.

Parameters:
  location-id - location id
  min-id      - return media before this min id (optional)
  max-id      - return media after this max id (optional)

get-recently-tagged-media

(get-recently-tagged-media tag)(get-recently-tagged-media tag {:keys [count min-tag-id max-tag-id]})
Get a list of recently tagged media.

Parameters:
  tag        - tag name
  count      - count of tagged media to return (optional)
  min-tag-id - return media before this min tag id (optional)
  max-tag-id - return media after this max tag id (optional)

get-relationship

(get-relationship user-id)
Get information about a relationship to another user. Relationships are expressed using the following terms in the
response:

* outgoing_status: Your relationship to the user. Can be 'follows', 'requested', 'none'
* incoming_status: A user's relationship to you. Can be 'followed_by', 'requested_by', 'blocked_by_you', 'none'

get-requested-by

(get-requested-by)
List the users who have requested this user's permission to follow.

get-tag

(get-tag tag)
Get information about a tag object.

get-user

(get-user)(get-user user-id)
Get information about a user. If user id is omitted returns information about the owner of the access token.

Parameters:
  user-id - user id (default: owner of the access token)

list-subscriptions

(list-subscriptions client-id client-secret)
List current subscriptions.

Parameters:
  client-id     - client id
  client-secret - client secret

modify-relationship

(modify-relationship user-id action)
Modify the relationship between the current user and the target user. Relationships are expressed using the following
terms in the response:

* outgoing_status: Your relationship to the user. Can be 'follows', 'requested', 'none'
* incoming_status: A user's relationship to you. Can be 'followed_by', 'requested_by', 'blocked_by_you', 'none'

Parameters:
  user-id - user id
  action  - action to perform: :follow, :unfollow, :approve or :ignore

remove-like

(remove-like media-id)
Remove a like on this media by the currently authenticated user.

request-access-token

(request-access-token client-id client-secret redirect-uri code)
Exchange code received from Instagram for an access token.

Parameters:
  client-id     - client ID
  client-secret - client secret
  redirect-uri  - the redirect URI used in the authorization request
  code          - the exact code received during the authorization step

search-locations

(search-locations {:keys [facebook-places-id lat lng distance]})
Search for a location by geographic coordinate or Facebook Places ID.

Parameters:
  facebook-places-id - returns a location mapped off of a Facebook places id.
                       (optional, if used, lat and lng are not required)
  lat                - latitude of the center search coordinate (optional, if used, lng is required)
  lng                - longitude of the center search coordinate (optional, if used, lat is required)
  distance           - distance in meters (optional, default 1000, max 5000)

search-media

(search-media lat lng)(search-media lat lng distance)
Search for recent media in a given area.

Parameters:
  lat      - latitude of the center search coordinate
  lng      - longitude of the center search coordinate
  distance - distance in meters (optional, default 1000, max 5000)

search-tags

(search-tags q)
Search for tags by name.

Parameters:
  q - a valid tag name without a leading # (eg. snowy, nofilter)

search-users

(search-users q)(search-users q count)
Get a list of users matching the query.

Parameters:
  q     - a query string
  count - number of users to return (optional)

set-like

(set-like media-id)
Set a like on this media by the currently authenticated user.

sign

(sign {:keys [url], :as req} client-secret)
Computes and adds signature to the request using given client secret.