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.
- checksums.yaml +4 -4
- data/lib/gramscraper.rb +44 -52
- metadata +4 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ee9e4076a44f02f5f6b45fd725c54abcebcac4a9
         | 
| 4 | 
            +
              data.tar.gz: 98b79c8896c02dbd23777d2a8b80396f7d71c299
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0dc6de7dd836ab7977af94272ee31cbd99fdbfaaa564957201f5190ea1f7ec2f277da59e028939ddec94d9bb15c27d65a79d4b1933ade2aab2dc80386117da30
         | 
| 7 | 
            +
              data.tar.gz: 2248846d7fa88457cbd9ad01fd9147e20cb46df425ec57caf96c223f165ccc4a6aff66ad3478a27b3cef7513db89bc888cd41aa8bf42dc92c67105958660ddd6
         | 
    
        data/lib/gramscraper.rb
    CHANGED
    
    | @@ -1,56 +1,48 @@ | |
| 1 1 | 
             
            require 'httparty'
         | 
| 2 2 |  | 
| 3 | 
            +
            # Gramscraper
         | 
| 3 4 | 
             
            class Gramscraper
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                 | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 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 | 
            -
             | 
| 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. | 
| 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- | 
| 11 | 
            +
            date: 2017-11-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 | 
            -
            description: A simple 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/ | 
| 20 | 
            +
            homepage: https://github.com/Gurenax/gramscraper
         | 
| 21 21 | 
             
            licenses:
         | 
| 22 22 | 
             
            - MIT
         | 
| 23 23 | 
             
            metadata: {}
         |