lita-hashtag 0.1.0 → 0.2.0
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/README.md +15 -2
 - data/lib/lita/handlers/hashtag.rb +19 -11
 - data/lita-hashtag.gemspec +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 41c386c0cddede38a39a826d8ce75df1cbda0c65
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3e51493b50558ec69043d92243f833d7dba1b178
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c86fd2b4749303444ac1ef0739e65b4c7fd7eee20b12ee0ebd60e595dd24bcf31fd1f538b0756bb6b096ff9eb1067b1b5f38bab463509fa0920478f3546daaea
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2138c0a1eb520d96c74519b73ef46e5b9b226f5c4564d250471b0111271bdd5a16877513039638c5713a3b204fc4ecc540c170017fd9db121195e8cc7eeb51ed
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -21,12 +21,25 @@ gem "lita-hashtag" 
     | 
|
| 
       21 
21 
     | 
    
         
             
            ### Optional
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
            * `config.handlers.hashtag.safe_search` - (String, Symbol) - The safe search
         
     | 
| 
       24 
     | 
    
         
            -
              setting to use when querying for images. Possible values are `: 
     | 
| 
       25 
     | 
    
         
            -
              `: 
     | 
| 
      
 24 
     | 
    
         
            +
              setting to use when querying for images. Possible values are `:high`,
         
     | 
| 
      
 25 
     | 
    
         
            +
              `:medium`, and `:off`. **Default:** `:medium`.
         
     | 
| 
      
 26 
     | 
    
         
            +
            * `config.handlers.hashtag.google_cse_id` - String - search engine id (see
         
     | 
| 
      
 27 
     | 
    
         
            +
              below)
         
     | 
| 
      
 28 
     | 
    
         
            +
            * `config.handlers.hashtag.google_cse_key` - String - api key (see below)
         
     | 
| 
       26 
29 
     | 
    
         
             
            * `config.handlers.hashtag.giphy_api_key` - String - Your Giphy API key. You can
         
     | 
| 
       27 
30 
     | 
    
         
             
              either email the devs for a personal API key, or you can use the default
         
     | 
| 
       28 
31 
     | 
    
         
             
              public beta key-- dc6zaTOxFJmzC. **Default:** `dc6zaTOxFJmzC`
         
     | 
| 
       29 
32 
     | 
    
         | 
| 
      
 33 
     | 
    
         
            +
            ## Important note about google custom search
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            Since google has shutdown their free image search API, you'll need to create an
         
     | 
| 
      
 36 
     | 
    
         
            +
            google custom search engine (https://cse.google.com/) allows 100 search per day
         
     | 
| 
      
 37 
     | 
    
         
            +
            free and fill in the `google_cse_key` with the 'search engine ID' (can be found
         
     | 
| 
      
 38 
     | 
    
         
            +
            under 'Basic'->'Details'->'Search engine ID'). Then you need to go create an
         
     | 
| 
      
 39 
     | 
    
         
            +
            api key from Google Developers Console (instructions here:
         
     | 
| 
      
 40 
     | 
    
         
            +
            https://developers.google.com/custom-search/json-api/v1/introduction) and fill
         
     | 
| 
      
 41 
     | 
    
         
            +
            that into the `google_cse_id`.
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
       30 
43 
     | 
    
         
             
            ## Usage
         
     | 
| 
       31 
44 
     | 
    
         | 
| 
       32 
45 
     | 
    
         
             
            ```
         
     | 
| 
         @@ -1,18 +1,21 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Lita
         
     | 
| 
       2 
2 
     | 
    
         
             
              module Handlers
         
     | 
| 
       3 
3 
     | 
    
         
             
                class Hashtag < Handler
         
     | 
| 
       4 
     | 
    
         
            -
                  URL = "https:// 
     | 
| 
      
 4 
     | 
    
         
            +
                  URL = "https://www.googleapis.com/customsearch/v1"
         
     | 
| 
       5 
5 
     | 
    
         
             
                  GIF_URL = "http://api.giphy.com/v1/gifs/search"
         
     | 
| 
       6 
     | 
    
         
            -
                  VALID_SAFE_VALUES = %w( 
     | 
| 
      
 6 
     | 
    
         
            +
                  VALID_SAFE_VALUES = %w(high medium off)
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                  config :safe_search, types: [String, Symbol], default: : 
     | 
| 
      
 8 
     | 
    
         
            +
                  config :safe_search, types: [String, Symbol], default: :medium do
         
     | 
| 
       9 
9 
     | 
    
         
             
                    validate do |value|
         
     | 
| 
       10 
10 
     | 
    
         
             
                      unless VALID_SAFE_VALUES.include?(value.to_s.strip)
         
     | 
| 
       11 
     | 
    
         
            -
                        "valid values are : 
     | 
| 
      
 11 
     | 
    
         
            +
                        "valid values are :high, :medium, or :off"
         
     | 
| 
       12 
12 
     | 
    
         
             
                      end
         
     | 
| 
       13 
13 
     | 
    
         
             
                    end
         
     | 
| 
       14 
14 
     | 
    
         
             
                  end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
      
 16 
     | 
    
         
            +
                  config :google_cse_id, type: String, required: true
         
     | 
| 
      
 17 
     | 
    
         
            +
                  config :google_cse_key, type: String, required: true
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       16 
19 
     | 
    
         
             
                  config :giphy_api_key, type: String, default: 'dc6zaTOxFJmzC'
         
     | 
| 
       17 
20 
     | 
    
         | 
| 
       18 
21 
     | 
    
         
             
                  route(/^#(.+)/, :fetch, command: false, help: {
         
     | 
| 
         @@ -24,31 +27,36 @@ module Lita 
     | 
|
| 
       24 
27 
     | 
    
         
             
                    query = response.matches[0][0]
         
     | 
| 
       25 
28 
     | 
    
         | 
| 
       26 
29 
     | 
    
         
             
                    if query[0] == '#'
         
     | 
| 
       27 
     | 
    
         
            -
                      response.reply get_gif(query)
         
     | 
| 
      
 30 
     | 
    
         
            +
                      response.reply get_gif(query[1..-1])
         
     | 
| 
       28 
31 
     | 
    
         
             
                    else
         
     | 
| 
       29 
32 
     | 
    
         
             
                      http_response = http.get(
         
     | 
| 
       30 
33 
     | 
    
         
             
                        URL,
         
     | 
| 
       31 
34 
     | 
    
         
             
                        v: "1.0",
         
     | 
| 
      
 35 
     | 
    
         
            +
                        searchType: 'image',
         
     | 
| 
       32 
36 
     | 
    
         
             
                        q: query,
         
     | 
| 
       33 
37 
     | 
    
         
             
                        safe: config.safe_search,
         
     | 
| 
       34 
     | 
    
         
            -
                         
     | 
| 
      
 38 
     | 
    
         
            +
                        fields: 'items(link)',
         
     | 
| 
      
 39 
     | 
    
         
            +
                        rsz: 8,
         
     | 
| 
      
 40 
     | 
    
         
            +
                        cx: config.google_cse_id,
         
     | 
| 
      
 41 
     | 
    
         
            +
                        key: config.google_cse_key
         
     | 
| 
       35 
42 
     | 
    
         
             
                      )
         
     | 
| 
       36 
43 
     | 
    
         | 
| 
       37 
44 
     | 
    
         
             
                      data = MultiJson.load(http_response.body)
         
     | 
| 
       38 
45 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                      if  
     | 
| 
       40 
     | 
    
         
            -
                        choice = data[" 
     | 
| 
      
 46 
     | 
    
         
            +
                      if http_response.status == 200
         
     | 
| 
      
 47 
     | 
    
         
            +
                        choice = data["items"].sample if data["items"]
         
     | 
| 
       41 
48 
     | 
    
         
             
                        if choice
         
     | 
| 
       42 
     | 
    
         
            -
                          response.reply ensure_extension(choice[" 
     | 
| 
      
 49 
     | 
    
         
            +
                          response.reply ensure_extension(choice["link"])
         
     | 
| 
       43 
50 
     | 
    
         
             
                        else
         
     | 
| 
       44 
     | 
    
         
            -
                          response.reply %{ 
     | 
| 
      
 51 
     | 
    
         
            +
                          response.reply %{What the hell is "#{query}"? Try something else.}
         
     | 
| 
       45 
52 
     | 
    
         
             
                        end
         
     | 
| 
       46 
53 
     | 
    
         
             
                      else
         
     | 
| 
       47 
     | 
    
         
            -
                        reason = data[" 
     | 
| 
      
 54 
     | 
    
         
            +
                        reason = data["error"]["message"] || "unknown error"
         
     | 
| 
       48 
55 
     | 
    
         
             
                        Lita.logger.warn(
         
     | 
| 
       49 
56 
     | 
    
         
             
                          "Couldn't get image from Google: #{reason}"
         
     | 
| 
       50 
57 
     | 
    
         
             
                        )
         
     | 
| 
       51 
58 
     | 
    
         
             
                      end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
       52 
60 
     | 
    
         
             
                    end
         
     | 
| 
       53 
61 
     | 
    
         
             
                  end
         
     | 
| 
       54 
62 
     | 
    
         | 
    
        data/lita-hashtag.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: lita-hashtag
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Richard Li
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-02-26 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: lita
         
     | 
| 
         @@ -126,3 +126,4 @@ summary: 'Let lita bot respond to #''s' 
     | 
|
| 
       126 
126 
     | 
    
         
             
            test_files:
         
     | 
| 
       127 
127 
     | 
    
         
             
            - spec/lita/handlers/hashtag_spec.rb
         
     | 
| 
       128 
128 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
      
 129 
     | 
    
         
            +
            has_rdoc: 
         
     |