shaken_not_stirred 0.0.7
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 +7 -0
- data/lib/configuration.rb +8 -0
- data/lib/shaken_not_stirred.rb +136 -0
- metadata +99 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: ef8bd79a93b648fcd5709aceba7de1edae0c976e
         | 
| 4 | 
            +
              data.tar.gz: 2c148b1b41cb4c3d045f4a22c69d08f839927718
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 64b9d39f4c4230e7b56701ed72b4d6ee9a1de7871c9f0734c6dec462f9e4e371928e39b67657c8282efb5259b1f8404cecec46783b4a3e1faef688c7ff1b3db8
         | 
| 7 | 
            +
              data.tar.gz: 910e9815d7c5066f0c45e93610d69b7c54b79468631f75b4d1262b84a72c1be5f5989b6291019e787374fb20d19c624263c28d9c7c7a9671390ec3686631324a
         | 
| @@ -0,0 +1,136 @@ | |
| 1 | 
            +
            require "configuration"
         | 
| 2 | 
            +
            require "httparty"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class ShakenNotStirred
         | 
| 5 | 
            +
              include HTTParty
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              # testing purposes
         | 
| 8 | 
            +
              # BASE_URL = "http://localhost:3000/api/v1".freeze
         | 
| 9 | 
            +
              BASE_URL = "https://api-cocktails.herokuapp.com/api/v1".freeze
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              attr_accessor :filters, :resource
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              class << self
         | 
| 14 | 
            +
                attr_accessor :configuration
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def self.configure
         | 
| 18 | 
            +
                self.configuration ||= Configuration.new
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                yield(configuration)
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def initialize
         | 
| 24 | 
            +
                @filters = {}
         | 
| 25 | 
            +
                @resource = "cocktails"
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              def by_name(query)
         | 
| 29 | 
            +
                apply_filter "name", query
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                self
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              def by_description(query)
         | 
| 35 | 
            +
                apply_filter "description", query
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                self
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              # "rum" | ["orange", "rum"]
         | 
| 41 | 
            +
              def by_ingredients(query)
         | 
| 42 | 
            +
                # "OR" behavior by default
         | 
| 43 | 
            +
                apply_filter_list "ingredients", query
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                self
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              # "classic" | ["classic", "new_era"]
         | 
| 49 | 
            +
              def by_categories(query)
         | 
| 50 | 
            +
                # "OR" behavior by default
         | 
| 51 | 
            +
                apply_filter_list "categories", query
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                self
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
              def by_timing(query)
         | 
| 57 | 
            +
                apply_filter "timing", query
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                self
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              def by_iba(query)
         | 
| 63 | 
            +
                apply_filter "iba", query
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                self
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              def by_rating(query)
         | 
| 69 | 
            +
                apply_filter "rating", query
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                self
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              def by_multiple(query)
         | 
| 75 | 
            +
                apply_filter "multiple", query
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                self
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              def by_page(page)
         | 
| 81 | 
            +
                apply_filter "page", page
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                self
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              def by_random(count=1)
         | 
| 87 | 
            +
                apply_filter "random", count
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                self
         | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
              def categories
         | 
| 93 | 
            +
                @resource = "categories"
         | 
| 94 | 
            +
                @results = []
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                self
         | 
| 97 | 
            +
              end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
              def ingredients
         | 
| 100 | 
            +
                @resource = "ingredients"
         | 
| 101 | 
            +
                @results = []
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                self
         | 
| 104 | 
            +
              end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
              def results
         | 
| 107 | 
            +
                @results = HTTParty.get(url, headers: headers)
         | 
| 108 | 
            +
              end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
              def url
         | 
| 111 | 
            +
                "#{BASE_URL}/#{@resource}?#{get_filters}"
         | 
| 112 | 
            +
              end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
              private
         | 
| 115 | 
            +
             | 
| 116 | 
            +
              def api_key
         | 
| 117 | 
            +
                @api_key ||= ShakenNotStirred.configuration.api_key
         | 
| 118 | 
            +
              end
         | 
| 119 | 
            +
             | 
| 120 | 
            +
              def apply_filter(filter_name, value)
         | 
| 121 | 
            +
                filters[filter_name] = value
         | 
| 122 | 
            +
              end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
              def apply_filter_list(filter_name, value)
         | 
| 125 | 
            +
                # categories[]=classic,new_era
         | 
| 126 | 
            +
                filters["#{filter_name}[]"] = [value].flatten.join(",")
         | 
| 127 | 
            +
              end
         | 
| 128 | 
            +
             | 
| 129 | 
            +
              def get_filters
         | 
| 130 | 
            +
                filters.map { |k,v| "#{k}=#{v}" }.join("&")
         | 
| 131 | 
            +
              end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
              def headers
         | 
| 134 | 
            +
                { "Authorization"=>"Token token=\"#{api_key}\"" }
         | 
| 135 | 
            +
              end
         | 
| 136 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,99 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: shaken_not_stirred
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Juan Roldan
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2020-06-08 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: httparty
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 0.15.7
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 0.15.7
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: vcr
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '3.0'
         | 
| 34 | 
            +
                - - ">="
         | 
| 35 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 36 | 
            +
                    version: 3.0.3
         | 
| 37 | 
            +
              type: :development
         | 
| 38 | 
            +
              prerelease: false
         | 
| 39 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 40 | 
            +
                requirements:
         | 
| 41 | 
            +
                - - "~>"
         | 
| 42 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 43 | 
            +
                    version: '3.0'
         | 
| 44 | 
            +
                - - ">="
         | 
| 45 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 46 | 
            +
                    version: 3.0.3
         | 
| 47 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 48 | 
            +
              name: webmock
         | 
| 49 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 50 | 
            +
                requirements:
         | 
| 51 | 
            +
                - - "~>"
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                    version: '2.3'
         | 
| 54 | 
            +
                - - ">="
         | 
| 55 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 56 | 
            +
                    version: 2.3.2
         | 
| 57 | 
            +
              type: :development
         | 
| 58 | 
            +
              prerelease: false
         | 
| 59 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 60 | 
            +
                requirements:
         | 
| 61 | 
            +
                - - "~>"
         | 
| 62 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 63 | 
            +
                    version: '2.3'
         | 
| 64 | 
            +
                - - ">="
         | 
| 65 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 66 | 
            +
                    version: 2.3.2
         | 
| 67 | 
            +
            description: Ruby client to interact with Cocktails API - https://juanroldan.com.ar/cocktails-api-landing
         | 
| 68 | 
            +
            email: juanroldan1989@gmail.com
         | 
| 69 | 
            +
            executables: []
         | 
| 70 | 
            +
            extensions: []
         | 
| 71 | 
            +
            extra_rdoc_files: []
         | 
| 72 | 
            +
            files:
         | 
| 73 | 
            +
            - lib/configuration.rb
         | 
| 74 | 
            +
            - lib/shaken_not_stirred.rb
         | 
| 75 | 
            +
            homepage: http://rubygems.org/gems/shaken_not_stirred
         | 
| 76 | 
            +
            licenses:
         | 
| 77 | 
            +
            - MIT
         | 
| 78 | 
            +
            metadata: {}
         | 
| 79 | 
            +
            post_install_message: 
         | 
| 80 | 
            +
            rdoc_options: []
         | 
| 81 | 
            +
            require_paths:
         | 
| 82 | 
            +
            - lib
         | 
| 83 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 84 | 
            +
              requirements:
         | 
| 85 | 
            +
              - - ">="
         | 
| 86 | 
            +
                - !ruby/object:Gem::Version
         | 
| 87 | 
            +
                  version: 2.3.1
         | 
| 88 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 89 | 
            +
              requirements:
         | 
| 90 | 
            +
              - - ">="
         | 
| 91 | 
            +
                - !ruby/object:Gem::Version
         | 
| 92 | 
            +
                  version: '0'
         | 
| 93 | 
            +
            requirements: []
         | 
| 94 | 
            +
            rubyforge_project: 
         | 
| 95 | 
            +
            rubygems_version: 2.5.1
         | 
| 96 | 
            +
            signing_key: 
         | 
| 97 | 
            +
            specification_version: 4
         | 
| 98 | 
            +
            summary: Shaken Not Stirred
         | 
| 99 | 
            +
            test_files: []
         |