coinmarketcap_lite 0.2.1 → 0.3.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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/coinmarketcap_lite.rb +114 -23
- metadata +42 -2
- metadata.gz.sig +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 10d5a6d57b2a240ace834efb0b2bb971b78f166286f0a82c05ebc160fba748ae
         | 
| 4 | 
            +
              data.tar.gz: 51c980988ab12110fb8ad0b5597599890a702ad9f1eafc0ac728ca34ef242e01
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ecbd394ed13c8806594c47babc2e05141e2016d532315bcbf4cc3c3f4e83930f85ff6ec79d04ecc8be4319ad8281d7a3bf4daeb44b1fd9cb7c1e00d570975220
         | 
| 7 | 
            +
              data.tar.gz: 7c757e285d4c2bfc231976e0ec1494c823263561a517ca2278c0400049433cdf871970c9957ae88b926ee6d4535e6a0313141090fc1ad90d32e45b47375f80c2
         | 
    
        checksums.yaml.gz.sig
    CHANGED
    
    | Binary file | 
    
        data.tar.gz.sig
    CHANGED
    
    | Binary file | 
    
        data/lib/coinmarketcap_lite.rb
    CHANGED
    
    | @@ -2,18 +2,56 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            # file: coinmarketcap_lite.rb
         | 
| 4 4 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
            require ' | 
| 5 | 
            +
             | 
| 6 | 
            +
            require 'excon'
         | 
| 7 | 
            +
            require 'did_you_mean'
         | 
| 7 8 | 
             
            require 'dynarex-password' # used by CoinmarketlitePlus
         | 
| 9 | 
            +
            require 'remote_dwsregistry'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            # see Coinmarketcap API documentation at
         | 
| 12 | 
            +
            #      https://coinmarketcap.com/api/documentation/v1
         | 
| 13 | 
            +
             | 
| 8 14 |  | 
| 15 | 
            +
            class CoinmarketcapLiteException < Exception
         | 
| 16 | 
            +
            end
         | 
| 9 17 |  | 
| 10 18 | 
             
            class CoinmarketcapLite
         | 
| 19 | 
            +
              using ColouredText
         | 
| 11 20 |  | 
| 12 21 | 
             
              def initialize(apikey: '', apiurl: 'https://pro-api.coinmarketcap.com', 
         | 
| 13 | 
            -
                              apibase: '/v1/cryptocurrency')
         | 
| 22 | 
            +
                              apibase: '/v1/cryptocurrency', filepath: '.', dym: true)
         | 
| 14 23 |  | 
| 15 24 | 
             
                @url_base = apiurl + apibase
         | 
| 16 | 
            -
                @apikey = apikey | 
| 25 | 
            +
                @apikey = apikey
         | 
| 26 | 
            +
                @filepath = filepath
         | 
| 27 | 
            +
                
         | 
| 28 | 
            +
                file = 'coinmarketlite.dat'
         | 
| 29 | 
            +
                if File.exists? file then
         | 
| 30 | 
            +
                  
         | 
| 31 | 
            +
                  File.open(File.join(@filepath, file)) do |f|  
         | 
| 32 | 
            +
                    @list = Marshal.load(f)  
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                    
         | 
| 35 | 
            +
                else
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  r = get_map()
         | 
| 38 | 
            +
                  puts 'r: ' +r.inspect[0..2000]
         | 
| 39 | 
            +
                  #exit
         | 
| 40 | 
            +
                  @list = r['data']
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  File.open(File.join(@filepath, file), 'w+') do |f|  
         | 
| 43 | 
            +
                    Marshal.dump(@list, f)  
         | 
| 44 | 
            +
                  end      
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
                
         | 
| 48 | 
            +
                if dym then
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  puts 'loading did_you_mean ...'.info if @debug          
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  @dym = DidYouMean::SpellChecker.new(dictionary: @list.flat_map \
         | 
| 53 | 
            +
                            {|x| [x['symbol'], x['name']]})
         | 
| 54 | 
            +
                end    
         | 
| 17 55 |  | 
| 18 56 | 
             
              end
         | 
| 19 57 |  | 
| @@ -24,39 +62,86 @@ class CoinmarketcapLite | |
| 24 62 | 
             
                if symbols.any? then
         | 
| 25 63 | 
             
                  get_map(symbols)
         | 
| 26 64 | 
             
                else
         | 
| 27 | 
            -
                   | 
| 65 | 
            +
                  # return the top 100 coins latest prices
         | 
| 66 | 
            +
                  api_call('/listings/latest',
         | 
| 28 67 | 
             
                              {"convert" => "USD,BTC", "limit" => "1","start" => "1"})
         | 
| 29 68 | 
             
                end
         | 
| 30 69 |  | 
| 31 70 | 
             
              end
         | 
| 71 | 
            +
              
         | 
| 72 | 
            +
              def find_coin(coin_name)
         | 
| 32 73 |  | 
| 33 | 
            -
             | 
| 34 | 
            -
              end
         | 
| 74 | 
            +
                #return coin_name unless @autofind
         | 
| 35 75 |  | 
| 36 | 
            -
             | 
| 76 | 
            +
                s = coin_name.to_s.downcase
         | 
| 77 | 
            +
                puts 's: ' + s.inspect if @debug
         | 
| 78 | 
            +
                r = @list.find {|coin| coin['symbol'].downcase == s || coin['name'].downcase == s}
         | 
| 79 | 
            +
                puts 'r: ' + r.inspect if @debug
         | 
| 80 | 
            +
                
         | 
| 81 | 
            +
                if r.nil? then
         | 
| 37 82 |  | 
| 38 | 
            -
             | 
| 83 | 
            +
                  if @dym then
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                    suggestion = @dym.correct coin_name
         | 
| 86 | 
            +
                    raise CoinmarketcapLiteException, "unknown coin or token name. \n"  \
         | 
| 87 | 
            +
                        + "Did you mean %s?" % [suggestion.first]
         | 
| 39 88 |  | 
| 40 | 
            -
             | 
| 89 | 
            +
                  else
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                    raise CoinmarketcapLiteException, "unknown coin or token name."
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                  end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                r
         | 
| 41 98 |  | 
| 42 99 | 
             
              end
         | 
| 43 100 |  | 
| 44 | 
            -
              def  | 
| 101 | 
            +
              def find_id(name)
         | 
| 102 | 
            +
                r = find_coin(name)
         | 
| 103 | 
            +
                r['id']
         | 
| 104 | 
            +
              end  
         | 
| 105 | 
            +
              
         | 
| 106 | 
            +
              def find_name(s)
         | 
| 107 | 
            +
                r = find_coin s
         | 
| 108 | 
            +
                r['name']
         | 
| 109 | 
            +
              end  
         | 
| 45 110 |  | 
| 46 | 
            -
             | 
| 111 | 
            +
              def get_historical_price()
         | 
| 112 | 
            +
              end
         | 
| 113 | 
            +
              
         | 
| 114 | 
            +
              def prices(coins=[])
         | 
| 115 | 
            +
                a = quotes(coins)
         | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
              
         | 
| 118 | 
            +
              def quotes(coins=[])
         | 
| 119 | 
            +
                
         | 
| 120 | 
            +
                coins = [coins] if coins.is_a? String
         | 
| 121 | 
            +
                ids = coins.map {|x| find_id(x)}
         | 
| 122 | 
            +
                api_call '/quotes/latest?id=' + ids.compact.join(',')    
         | 
| 123 | 
            +
              end
         | 
| 47 124 |  | 
| 48 | 
            -
             | 
| 49 | 
            -
                request["X-CMC_PRO_API_KEY"] = @apikey
         | 
| 50 | 
            -
                request["Accept"] = "application/json"
         | 
| 51 | 
            -
                request.set_form_data( data )
         | 
| 125 | 
            +
              private
         | 
| 52 126 |  | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 127 | 
            +
              # returns the coin mapping info (i.e. symbol, slug, name etc.)
         | 
| 128 | 
            +
              #
         | 
| 129 | 
            +
              def get_map(symbols=[])
         | 
| 130 | 
            +
                return get_request('/map') if symbols.empty?
         | 
| 131 | 
            +
                api_call('/map?symbol=' + symbols.map {|x| x.to_s.upcase}).join(',')
         | 
| 56 132 |  | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 133 | 
            +
              end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
              def api_call(api, data={})
         | 
| 136 | 
            +
                
         | 
| 137 | 
            +
                url = @url_base + api
         | 
| 138 | 
            +
                h = {}
         | 
| 139 | 
            +
                h["X-CMC_PRO_API_KEY"] = @apikey
         | 
| 140 | 
            +
                h["Accept"] = "application/json"
         | 
| 141 | 
            +
                connection = Excon.new(url, :headers => h)
         | 
| 142 | 
            +
                r = connection.request(:method => 'GET')
         | 
| 143 | 
            +
                #return r
         | 
| 144 | 
            +
                return JSON.parse(r.body)    
         | 
| 60 145 |  | 
| 61 146 | 
             
              end
         | 
| 62 147 | 
             
            end
         | 
| @@ -64,7 +149,13 @@ end | |
| 64 149 |  | 
| 65 150 | 
             
            class CoinmarketcapLitePlus < CoinmarketcapLite
         | 
| 66 151 |  | 
| 67 | 
            -
              def self.fetch_apikey( | 
| 152 | 
            +
              def self.fetch_apikey(regx)
         | 
| 153 | 
            +
                
         | 
| 154 | 
            +
                reg = if regx.is_a? String then
         | 
| 155 | 
            +
                  RemoteDwsRegistry.new domain: regx
         | 
| 156 | 
            +
                else
         | 
| 157 | 
            +
                  regx
         | 
| 158 | 
            +
                end
         | 
| 68 159 |  | 
| 69 160 | 
             
                decipher = ->(lookup_file, s) {
         | 
| 70 161 | 
             
                  DynarexPassword.new.reverse_lookup(s, lookup_file)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: coinmarketcap_lite
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - James Robertson
         | 
| @@ -35,8 +35,28 @@ cert_chain: | |
| 35 35 | 
             
              9pxUgkdUQ+NiNSK4rcJvdaDNZSKeZeodRiCckztoJb2bHj1kJRCtbIJMWMmT4QUs
         | 
| 36 36 | 
             
              0H4+XrUgxuhbU9yiMh5hw2T5
         | 
| 37 37 | 
             
              -----END CERTIFICATE-----
         | 
| 38 | 
            -
            date: 2021-05- | 
| 38 | 
            +
            date: 2021-05-05 00:00:00.000000000 Z
         | 
| 39 39 | 
             
            dependencies:
         | 
| 40 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 41 | 
            +
              name: excon
         | 
| 42 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 43 | 
            +
                requirements:
         | 
| 44 | 
            +
                - - ">="
         | 
| 45 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 46 | 
            +
                    version: 0.81.0
         | 
| 47 | 
            +
                - - "~>"
         | 
| 48 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            +
                    version: '0.81'
         | 
| 50 | 
            +
              type: :runtime
         | 
| 51 | 
            +
              prerelease: false
         | 
| 52 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 53 | 
            +
                requirements:
         | 
| 54 | 
            +
                - - ">="
         | 
| 55 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 56 | 
            +
                    version: 0.81.0
         | 
| 57 | 
            +
                - - "~>"
         | 
| 58 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 59 | 
            +
                    version: '0.81'
         | 
| 40 60 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 41 61 | 
             
              name: dynarex-password
         | 
| 42 62 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -57,6 +77,26 @@ dependencies: | |
| 57 77 | 
             
                - - "~>"
         | 
| 58 78 | 
             
                  - !ruby/object:Gem::Version
         | 
| 59 79 | 
             
                    version: '0.2'
         | 
| 80 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 81 | 
            +
              name: remote_dwsregistry
         | 
| 82 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 83 | 
            +
                requirements:
         | 
| 84 | 
            +
                - - "~>"
         | 
| 85 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 86 | 
            +
                    version: '0.4'
         | 
| 87 | 
            +
                - - ">="
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: 0.4.1
         | 
| 90 | 
            +
              type: :runtime
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0.4'
         | 
| 97 | 
            +
                - - ">="
         | 
| 98 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 99 | 
            +
                    version: 0.4.1
         | 
| 60 100 | 
             
            description: 
         | 
| 61 101 | 
             
            email: digital.robertson@gmail.com
         | 
| 62 102 | 
             
            executables: []
         | 
    
        metadata.gz.sig
    CHANGED
    
    | Binary file |