gramscraper 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gramscraper.rb +44 -52
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3beac7a4c1df901c026fc922a31a31437be89ca6
4
- data.tar.gz: d8c3f58c652ac8bbddbb5060816a1b8f264e8372
3
+ metadata.gz: ee9e4076a44f02f5f6b45fd725c54abcebcac4a9
4
+ data.tar.gz: 98b79c8896c02dbd23777d2a8b80396f7d71c299
5
5
  SHA512:
6
- metadata.gz: 9ac4e95537361f7ddb4c89759b652394fce741cf05ff6badf1c97d1960d47a59eb95a5d6ddcd30d60fbff6d389cb1159bfa8e433f9d6c0ce3d50335860d43d51
7
- data.tar.gz: 54f9193a94e0194e7208b31698eb686f2aca249eee1e0c4ce4c6d5c1b548bff8ced8643008b8e1d7737a47fb56f117f7930566c1d6d0646c47f4a8d0ee7f4892
6
+ metadata.gz: 0dc6de7dd836ab7977af94272ee31cbd99fdbfaaa564957201f5190ea1f7ec2f277da59e028939ddec94d9bb15c27d65a79d4b1933ade2aab2dc80386117da30
7
+ data.tar.gz: 2248846d7fa88457cbd9ad01fd9147e20cb46df425ec57caf96c223f165ccc4a6aff66ad3478a27b3cef7513db89bc888cd41aa8bf42dc92c67105958660ddd6
@@ -1,56 +1,48 @@
1
1
  require 'httparty'
2
2
 
3
+ # Gramscraper
3
4
  class Gramscraper
4
-
5
- def self.scrape(username)
6
- # Base URL for instagram media
7
- base_url = "https://www.instagram.com/#{username}/media"
8
-
9
- # Initialise the url (without max_id token)
10
- url = base_url
11
-
12
- # Initialise instagram array
13
- instagram = Array.new
14
-
15
- while true
16
- # Use HTTParty to retrieve the JSON response
17
- page = HTTParty.get(url).parsed_response
18
-
19
- # Reset last_id
20
- last_id = ""
21
-
22
- page["items"].each do |page_item|
23
-
24
- # Post ID
25
- last_id = page_item["id"]
26
-
27
- # Image Caption
28
- caption = page_item["caption"]["text"] unless page_item["caption"].nil?
29
-
30
- # Get images in every resolution available
31
- thumbnail = page_item["images"]["thumbnail"]["url"] unless page_item["images"].nil?
32
- low_resolution = page_item["images"]["low_resolution"]["url"] unless page_item["images"].nil?
33
- standard_resolution = page_item["images"]["standard_resolution"]["url"] unless page_item["images"].nil?
34
-
35
- # Copy data to hash
36
- instagram_item = {
37
- :last_id => last_id, :caption => caption, :thumbnail => thumbnail, :low_resolution => low_resolution, :standard_resolution => standard_resolution,
38
- }
39
-
40
- # Add instagram item hash to array
41
- instagram << instagram_item
42
- end
43
-
44
- # If there are more photos to scraper, capture the last_id and use it as token to ?max_id=
45
- if page["more_available"]==true
46
- next_page_token = "/?max_id=#{last_id}" # e.g. /?max_id=1537732482693479519_54429723
47
- url = base_url + next_page_token
48
-
49
- # Else there are no more photos so end the loop
50
- else
51
- break
52
- end
53
- end
54
- instagram
5
+ def self.scrape(access_token, username="self")
6
+ # Base URL for instagram media
7
+ base_url = "https://api.instagram.com/v1/users/#{username}/media/recent/?access_token=#{access_token}"
8
+
9
+ # Initialise the url (without max_id token)
10
+ url = base_url
11
+
12
+ # Initialise instagram array
13
+ instagram = []
14
+
15
+ # Use HTTParty to retrieve the JSON response
16
+ page = HTTParty.get(url).parsed_response
17
+
18
+ # Reset last_id
19
+ last_id = ''
20
+ page['data'].each do |page_item|
21
+ # Post ID
22
+ last_id = page_item['id']
23
+
24
+ # Image Caption
25
+ caption = page_item['caption']['text'] unless page_item['caption'].nil?
26
+
27
+ # Get images in every resolution available
28
+ unless page_item['images'].nil?
29
+ thumbnail = page_item['images']['thumbnail']['url']
30
+ low_resolution = page_item['images']['low_resolution']['url']
31
+ standard_resolution = page_item['images']['standard_resolution']['url']
32
+ end
33
+
34
+ # Copy data to hash
35
+ instagram_item = {
36
+ last_id: last_id,
37
+ caption: caption,
38
+ thumbnail: thumbnail,
39
+ low_resolution: low_resolution,
40
+ standard_resolution: standard_resolution,
41
+ }
42
+
43
+ # Add instagram item hash to array
44
+ instagram << instagram_item
55
45
  end
56
- end
46
+ instagram
47
+ end
48
+ end
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gramscraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Dimaliwat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2017-11-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple instagram scraping gem which retrieves all your photos in instagram.
13
+ description: A simple instagram gem which retrieves your recent photos from instagram.
14
14
  email: glenn.dimaliwat@gmail.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/gramscraper.rb
20
- homepage: https://github.com/GlennDimaliwat/gramscraper
20
+ homepage: https://github.com/Gurenax/gramscraper
21
21
  licenses:
22
22
  - MIT
23
23
  metadata: {}