bittrex-enterprise 0.1.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.
@@ -0,0 +1,92 @@
1
+ module BittrexEnterprise
2
+ class Markets
3
+ include ApiHelpers
4
+
5
+ # ==============================================================================================
6
+ # PUBLIC METHODS - NO AUTH REQUIRED ============================================================
7
+ # ==============================================================================================
8
+
9
+ # ------------------------------------- LIST -------------------------------------------------
10
+ # List markets
11
+ # --------------------------------------------------------------------------------------------
12
+ def self.list
13
+ get 'markets'
14
+ end
15
+
16
+
17
+ # ----------------------------------- SUMMARIES ----------------------------------------------
18
+ # List summaries of the last 24 hours of activity for all markets.
19
+ # --------------------------------------------------------------------------------------------
20
+ def self.summaries
21
+ get 'markets/summaries'
22
+ end
23
+
24
+
25
+ # ------------------------------------ INFO --------------------------------------------------
26
+ # Retrieve information for a specific market.
27
+ # ------ PARAMS ------
28
+ # market_symbol: string - required - symbol of market to retrieve
29
+ # --------------------------------------------------------------------------------------------
30
+ def self.info(market_symbol)
31
+ get 'markets/{marketSymbol}', marketSymbol: market_symbol
32
+ end
33
+
34
+
35
+ # ----------------------------------- SUMMARY ------------------------------------------------
36
+ # Retrieve summary of the last 24 hours of activity for a specific market.
37
+ # ------ PARAMS ------
38
+ # market_symbol: string - required - symbol of market to retrieve summary for
39
+ # --------------------------------------------------------------------------------------------
40
+ def self.summary(market_symbol)
41
+ get 'markets/{marketSymbol}/summary', marketSymbol: market_symbol
42
+ end
43
+
44
+
45
+ # ---------------------------------- ORDER BOOK ----------------------------------------------
46
+ # Retrieve the order book for a specific market.
47
+ # ------ PARAMS ------
48
+ # market_symbol: string - required - symbol of market to retrieve order book for
49
+ # depth: integer - optional - maximum depth of order book to return
50
+ # (allowed values are [1, 25, 500], default is 25)
51
+ # --------------------------------------------------------------------------------------------
52
+ def self.order_book(market_symbol, depth=nil)
53
+ get 'markets/{marketSymbol}/orderbook', marketSymbol: market_symbol, depth: depth
54
+ end
55
+
56
+
57
+ # ------------------------------------ TRADES ------------------------------------------------
58
+ # Retrieve the recent trades for a specific market.
59
+ # ------ PARAMS ------
60
+ # market_symbol: string - required - symbol of market to retrieve recent trades for
61
+ # --------------------------------------------------------------------------------------------
62
+ def self.trades(market_symbol)
63
+ get 'markets/{marketSymbol}/trades', marketSymbol: market_symbol
64
+ end
65
+
66
+
67
+ # ----------------------------------- TICKER -------------------------------------------------
68
+ # Retrieve the ticker for a specific market.
69
+ # ------ PARAMS ------
70
+ # market_symbol: string - required - symbol of market to retrieve recent trades for
71
+ # --------------------------------------------------------------------------------------------
72
+ def self.ticker(market_symbol)
73
+ get 'markets/{marketSymbol}/trades', marketSymbol: market_symbol
74
+ end
75
+
76
+
77
+ # ----------------------------------- CANDLES ------------------------------------------------
78
+ # Retrieve recent candles for a specific market. The maximum age of the returned candles
79
+ # depends on the interval as follows:
80
+ # (MINUTE_1: 1 day, MINUTE_5: 1 day, HOUR_1: 31 days, DAY_1: 366 days).
81
+ # Candles for intervals without any trading activity are omitted.
82
+ # ------ PARAMS ------
83
+ # market_symbol: string - required - symbol of market to retrieve recent trades for
84
+ # candle_interval: string_enum - required - desired time interval between candles -
85
+ # [MINUTE_1, MINUTE_5, HOUR_1, DAY_1]
86
+ # --------------------------------------------------------------------------------------------
87
+ def self.candles(market_symbol, candle_interval)
88
+ get 'markets/{marketSymbol}/trades', marketSymbol: market_symbol, candleInterval: candle_interval
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,98 @@
1
+ module BittrexEnterprise
2
+ class Orders
3
+ include ApiHelpers
4
+
5
+ # ==============================================================================================
6
+ # AUTH REQUIRED ================================================================================
7
+ # ==============================================================================================
8
+
9
+ # ----------------------------------------- OPEN ---------------------------------------------
10
+ # List open deposits. Results are sorted in inverse order of UpdatedAt, and are limited to
11
+ # the first 1000.
12
+ #
13
+ # ------ PARAMS ------ PARAMS MUST BE PASSED AS KEY VALUE PAIRS
14
+ # marketSymbol - string - optional - filter by market
15
+ # --------------------------------------------------------------------------------------------
16
+ def self.open(params={})
17
+ get_signed 'orders/open', params
18
+ end
19
+
20
+
21
+ # ---------------------------------------- CLOSED --------------------------------------------
22
+ # List closed orders.
23
+ # StartDate and EndDate filters apply to the ClosedAt field. Pagination and the sort order
24
+ # of the results are in inverse order of the ClosedAt field.
25
+ #
26
+ # ------ PARAMS ------ PARAMS MUST BE PASSED AS KEY VALUE PAIRS
27
+ # marketSymbol - string - optional - filter by market
28
+ #
29
+ # nextPageToken - string - The unique identifier of the item that the resulting query result
30
+ # should start after, in the sort order of the given endpoint. Used for traversing
31
+ # a paginated set in the forward direction. (May only be specified if PreviousPageToken
32
+ # is not specified.)
33
+ #
34
+ # previousPageToken - string - The unique identifier of the item that the resulting query
35
+ # result should end before, in the sort order of the given endpoint. Used for traversing
36
+ # a paginated set in the reverse direction. (May only be specified if NextPageToken is
37
+ # not specified.)
38
+ #
39
+ # pageSize - integer - maximum number of items to retrieve -- default 100, minimum 1, maximum 200
40
+ #
41
+ # startDate - string(date-time) - Filters out results before this timestamp. In ISO 8601 format
42
+ # (e.g., "2019-01-02T16:23:45Z"). Precision beyond one second is not supported. Use
43
+ # pagination parameters for more precise filtering.
44
+ #
45
+ # endDate - string(date-time) - Filters out result after this timestamp. Uses the same format
46
+ # as StartDate. Either, both, or neither of StartDate and EndDate can be set. The only
47
+ # constraint on the pair is that, if both are set, then EndDate cannot be before StartDate.
48
+ # --------------------------------------------------------------------------------------------
49
+ def self.closed(params={})
50
+ get_signed 'orders/closed', params
51
+ end
52
+
53
+
54
+ # --------------------------------------- RETRIEVE -------------------------------------------
55
+ # Retrieve information on a specific order.
56
+ #
57
+ # ------ PARAMS ------
58
+ # order_id - string - required - (guid-formatted string) - ID of the order to retrieve
59
+ # --------------------------------------------------------------------------------------------
60
+ def self.retrieve(order_id)
61
+ get_signed 'orders/{orderId}', orderId: order_id
62
+ end
63
+
64
+ # ---------------------------------------- CANCEL --------------------------------------------
65
+ # Cancel an order.
66
+ #
67
+ # ------ PARAMS ------
68
+ # order_id - string - required - (guid-formatted string) - ID of the order to retrieve
69
+ # --------------------------------------------------------------------------------------------
70
+ def self.cancel(order_id)
71
+ delete_signed 'orders/{orderId}', orderId: order_id
72
+ end
73
+
74
+
75
+ # ---------------------------------------- CREATE --------------------------------------------
76
+ # Create a new order.
77
+ #
78
+ # ------ PARAMS ------
79
+ # NewOrder - object - required - information specifying the order to create
80
+ # {
81
+ # "marketSymbol": "string",
82
+ # "direction": "string",
83
+ # "type": "string",
84
+ # "quantity": "number (double)",
85
+ # "ceiling": "number (double)",
86
+ # "limit": "number (double)",
87
+ # "timeInForce": "string",
88
+ # "expiresAt": "string (date-time)",
89
+ # "clientOrderId": "string (uuid)"
90
+ # }
91
+ # *** REQUIRED - marketSymbol, direction, type ***
92
+ # --------------------------------------------------------------------------------------------
93
+ def self.create(new_order)
94
+ post_signed 'orders', new_order
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,17 @@
1
+ module BittrexEnterprise
2
+ class Ping
3
+ include ApiHelpers
4
+
5
+ # ==============================================================================================
6
+ # PUBLIC METHODS - NO AUTH REQUIRED ================================================================================
7
+ # ==============================================================================================
8
+
9
+ # ----------------------------------------- PING -----------------------------------------
10
+ # Pings the service
11
+ # --------------------------------------------------------------------------------------------
12
+ def self.send
13
+ get 'ping'
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,55 @@
1
+ module BittrexEnterprise
2
+ class SubAccounts
3
+ include ApiHelpers
4
+
5
+ # ==============================================================================================
6
+ # AUTH REQUIRED ================================================================================
7
+ # ==============================================================================================
8
+
9
+ # ------------------------------------------ LIST --------------------------------------------
10
+ # List subaccounts. (NOTE: This API is limited to partners and not available for traders.)
11
+ # Pagination and the sort order of the results are in inverse order of the CreatedAt field.
12
+ #
13
+ # ------ PARAMS ------ PARAMS MUST BE PASSED AS KEY VALUE PAIRS
14
+ # nextPageToken - string - The unique identifier of the item that the resulting query result
15
+ # should start after, in the sort order of the given endpoint. Used for traversing
16
+ # a paginated set in the forward direction. (May only be specified if PreviousPageToken
17
+ # is not specified.)
18
+ #
19
+ # previousPageToken - string - The unique identifier of the item that the resulting query
20
+ # result should end before, in the sort order of the given endpoint. Used for traversing
21
+ # a paginated set in the reverse direction. (May only be specified if NextPageToken is
22
+ # not specified.)
23
+ #
24
+ # pageSize - integer - maximum number of items to retrieve -- default 100, minimum 1, maximum 200
25
+ # --------------------------------------------------------------------------------------------
26
+ def self.list(params={})
27
+ get_signed 'subaccounts', params
28
+ end
29
+
30
+
31
+ # ------------------------------------------ CREATE ------------------------------------------
32
+ # Create a new subaccount. (NOTE: This API is limited to partners and not available for traders.)
33
+ #
34
+ # ------ PARAMS ------
35
+ # no params required. Passes an empty hash
36
+ # --------------------------------------------------------------------------------------------
37
+ def self.create()
38
+ post_signed 'subaccounts', {}
39
+ end
40
+
41
+
42
+ # --------------------------------------- RETRIEVE -------------------------------------------
43
+ # Retrieve details for a specified subaccount. (NOTE: This API is limited to partners
44
+ # and not available for traders.)
45
+ #
46
+ # ------ PARAMS ------
47
+ # sub_account_id - string - required - (guid-formatted string) - ID of the subaccount to
48
+ # retrieve details for
49
+ # --------------------------------------------------------------------------------------------
50
+ def self.retrieve(sub_account_id)
51
+ get_signed 'subaccounts/{subaccountId}', subaccountId: sub_account_id
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,111 @@
1
+ module BittrexEnterprise
2
+ class Transfers
3
+ include ApiHelpers
4
+
5
+ # ==============================================================================================
6
+ # AUTH REQUIRED ================================================================================
7
+ # ==============================================================================================
8
+
9
+ # ----------------------------------------- SENT ---------------------------------------------
10
+ # List sent transfers. (NOTE: This API is limited to partners and not available for traders.)
11
+ # Pagination and the sort order of the results are in inverse order of the Executed field.
12
+ #
13
+ # ------ PARAMS ------ PARAMS MUST BE PASSED AS KEY VALUE PAIRS
14
+ # toSubaccountId - string - optional
15
+ #
16
+ # toMasterAccount - boolean - optional
17
+ #
18
+ # currencySymbol - string - optional
19
+ #
20
+ # nextPageToken - string - The unique identifier of the item that the resulting query result
21
+ # should start after, in the sort order of the given endpoint. Used for traversing
22
+ # a paginated set in the forward direction. (May only be specified if PreviousPageToken
23
+ # is not specified.)
24
+ #
25
+ # previousPageToken - string - The unique identifier of the item that the resulting query
26
+ # result should end before, in the sort order of the given endpoint. Used for traversing
27
+ # a paginated set in the reverse direction. (May only be specified if NextPageToken is
28
+ # not specified.)
29
+ #
30
+ # pageSize - integer - maximum number of items to retrieve -- default 100, minimum 1, maximum 200
31
+ #
32
+ # startDate - string(date-time) - Filters out results before this timestamp. In ISO 8601 format
33
+ # (e.g., "2019-01-02T16:23:45Z"). Precision beyond one second is not supported. Use
34
+ # pagination parameters for more precise filtering.
35
+ #
36
+ # endDate - string(date-time) - Filters out result after this timestamp. Uses the same format
37
+ # as StartDate. Either, both, or neither of StartDate and EndDate can be set. The only
38
+ # constraint on the pair is that, if both are set, then EndDate cannot be before StartDate.
39
+ # --------------------------------------------------------------------------------------------
40
+ def self.sent(params={})
41
+ get_signed 'transfers/sent', params
42
+ end
43
+
44
+
45
+ # -------------------------------------- RECEIVED --------------------------------------------
46
+ # List sent transfers. (NOTE: This API is limited to partners and not available for traders.)
47
+ # Pagination and the sort order of the results are in inverse order of the Executed field.
48
+ #
49
+ # ------ PARAMS ------ PARAMS MUST BE PASSED AS KEY VALUE PAIRS
50
+ # fromSubaccountId - string - optional
51
+ #
52
+ # fromMasterAccount - boolean - optional
53
+ #
54
+ # currencySymbol - string - optional
55
+ #
56
+ # nextPageToken - string - The unique identifier of the item that the resulting query result
57
+ # should start after, in the sort order of the given endpoint. Used for traversing
58
+ # a paginated set in the forward direction. (May only be specified if PreviousPageToken
59
+ # is not specified.)
60
+ #
61
+ # previousPageToken - string - The unique identifier of the item that the resulting query
62
+ # result should end before, in the sort order of the given endpoint. Used for traversing
63
+ # a paginated set in the reverse direction. (May only be specified if NextPageToken is
64
+ # not specified.)
65
+ #
66
+ # pageSize - integer - maximum number of items to retrieve -- default 100, minimum 1, maximum 200
67
+ #
68
+ # startDate - string(date-time) - Filters out results before this timestamp. In ISO 8601 format
69
+ # (e.g., "2019-01-02T16:23:45Z"). Precision beyond one second is not supported. Use
70
+ # pagination parameters for more precise filtering.
71
+ #
72
+ # endDate - string(date-time) - Filters out result after this timestamp. Uses the same format
73
+ # as StartDate. Either, both, or neither of StartDate and EndDate can be set. The only
74
+ # constraint on the pair is that, if both are set, then EndDate cannot be before StartDate.
75
+ # --------------------------------------------------------------------------------------------
76
+ def self.received(params={})
77
+ get_signed 'transfers/received', params
78
+ end
79
+
80
+
81
+ # --------------------------------------- RETRIEVE -------------------------------------------
82
+ # Retrieve information on the specified transfer. (NOTE: This API is limited to partners and
83
+ # not available for traders.)
84
+ #
85
+ # ------ PARAMS ------
86
+ # transfer_id - string - required - (guid-formatted string) - ID of the transfer to retrieve
87
+ # --------------------------------------------------------------------------------------------
88
+ def self.retrieve(transfer_id)
89
+ get_signed 'transfers/{transferId}', transferId: transfer_id
90
+ end
91
+
92
+ # ---------------------------------------- CREATE --------------------------------------------
93
+ # Executes a new transfer. (NOTE: This API is limited to partners and not available for traders.)
94
+ #
95
+ # ------ PARAMS ------
96
+ # NewTransfer - object - required - information specifying the transfer to execute
97
+ # {
98
+ # "toSubaccountId": "string (uuid)",
99
+ # "requestId": "string (uuid)",
100
+ # "currencySymbol": "string",
101
+ # "amount": "number (double)",
102
+ # "toMasterAccount": "boolean"
103
+ # }
104
+ # *** REQUIRED - currencySymbol, amount ***
105
+ # --------------------------------------------------------------------------------------------
106
+ def self.create(new_transfer)
107
+ post_signed 'transfers', new_transfer
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ module BittrexEnterprise
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,115 @@
1
+ module BittrexEnterprise
2
+ class Withdrawals
3
+ include ApiHelpers
4
+
5
+ # ==============================================================================================
6
+ # AUTH REQUIRED ================================================================================
7
+ # ==============================================================================================
8
+
9
+ # ----------------------------------------- OPEN ---------------------------------------------
10
+ # List open withdrawals. Results are sorted in inverse order of the CreatedAt field, and are
11
+ # limited to the first 1000.
12
+ #
13
+ # ------ PARAMS ------ PARAMS MUST BE PASSED AS KEY VALUE PAIRS
14
+ # status - string enum: [REQUESTED, AUTHORIZED, PENDING, ERROR_INVALID_ADDRESS] - optional -
15
+ # filter by an open withdrawal status
16
+ #
17
+ # currencySymbol - string - optional - filter by currency
18
+ # --------------------------------------------------------------------------------------------
19
+ def self.open(params={})
20
+ get_signed 'withdrawals/open', params
21
+ end
22
+
23
+
24
+ # ---------------------------------------- CLOSED --------------------------------------------
25
+ # List closed withdrawals. StartDate and EndDate filters apply to the CompletedAt field.
26
+ # Pagination and the sort order of the results are in inverse order of the CompletedAt field.
27
+ #
28
+ # ------ PARAMS ------ PARAMS MUST BE PASSED AS KEY VALUE PAIRS
29
+ # status - string enum: [COMPLETED, CANCELLED] - optional - filter by an open withdrawal status
30
+ #
31
+ # currencySymbol - string - optional - filter by currency
32
+ #
33
+ # nextPageToken - string - The unique identifier of the item that the resulting query result
34
+ # should start after, in the sort order of the given endpoint. Used for traversing
35
+ # a paginated set in the forward direction. (May only be specified if PreviousPageToken
36
+ # is not specified.)
37
+ #
38
+ # previousPageToken - string - The unique identifier of the item that the resulting query
39
+ # result should end before, in the sort order of the given endpoint. Used for traversing
40
+ # a paginated set in the reverse direction. (May only be specified if NextPageToken is
41
+ # not specified.)
42
+ #
43
+ # pageSize - integer - maximum number of items to retrieve -- default 100, minimum 1, maximum 200
44
+ #
45
+ # startDate - string(date-time) - Filters out results before this timestamp. In ISO 8601 format
46
+ # (e.g., "2019-01-02T16:23:45Z"). Precision beyond one second is not supported. Use
47
+ # pagination parameters for more precise filtering.
48
+ #
49
+ # endDate - string(date-time) - Filters out result after this timestamp. Uses the same format
50
+ # as StartDate. Either, both, or neither of StartDate and EndDate can be set. The only
51
+ # constraint on the pair is that, if both are set, then EndDate cannot be before StartDate.
52
+ # --------------------------------------------------------------------------------------------
53
+ def self.closed(params={})
54
+ get_signed 'withdrawals/closed', params
55
+ end
56
+
57
+
58
+ # --------------------------------------- BY TX ID -------------------------------------------
59
+ # Retrieves all withdrawals for this account with the given TxId
60
+ #
61
+ # ------ PARAMS ------
62
+ # tx_id - string - required - the transaction id to lookup
63
+ # --------------------------------------------------------------------------------------------
64
+ def self.by_tx_id(tx_id)
65
+ get_signed 'withdrawals/ByTxId/{txId}', txId: tx_id
66
+ end
67
+
68
+
69
+ # --------------------------------------- RETRIEVE -------------------------------------------
70
+ # Retrieve information on a specified withdrawal.
71
+ #
72
+ # ------ PARAMS ------
73
+ # withdrawal_id - string - required - (guid-formatted string) - ID of withdrawal to retrieve
74
+ # --------------------------------------------------------------------------------------------
75
+ def self.by_tx_id(withdrawal_id)
76
+ get_signed 'withdrawals/{withdrawalId}', withdrawalId: tx_id
77
+ end
78
+
79
+
80
+ # ---------------------------------------- CANCEL --------------------------------------------
81
+ # Cancel an order.
82
+ #
83
+ # ------ PARAMS ------
84
+ # withdrawal_id - string - required - (guid-formatted string) - ID of withdrawal to cancel
85
+ # --------------------------------------------------------------------------------------------
86
+ def self.cancel(withdrawal_id)
87
+ delete_signed 'withdrawals/{withdrawalId}', withdrawalId: withdrawal_id
88
+ end
89
+
90
+
91
+ # ---------------------------------------- CREATE --------------------------------------------
92
+ # Create a new withdrawal.
93
+ #
94
+ # ------ PARAMS ------
95
+ # NewWithdrawal - object - required - information specifying the withdrawal to create
96
+ # {
97
+ # "id": "string (uuid)",
98
+ # "currencySymbol": "string",
99
+ # "quantity": "number (double)",
100
+ # "cryptoAddress": "string",
101
+ # "cryptoAddressTag": "string",
102
+ # "txCost": "number (double)",
103
+ # "txId": "string",
104
+ # "status": "string",
105
+ # "createdAt": "string (date-time)",
106
+ # "completedAt": "string (date-time)"
107
+ # }
108
+ # *** REQUIRED - id, currencySymbol, quantity, cryptoAddress, status, createdAt ***
109
+ # --------------------------------------------------------------------------------------------
110
+ def self.create(new_withdrawal)
111
+ post_signed 'withdrawals', new_withdrawal
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,46 @@
1
+ require 'openssl'
2
+ require 'digest'
3
+ require 'addressable/uri'
4
+ require 'deep_symbolize'
5
+ require 'json'
6
+ require 'httparty'
7
+
8
+ require 'bittrex-enterprise/version'
9
+ require 'bittrex-enterprise/api_helpers'
10
+ require 'bittrex-enterprise/account'
11
+ require 'bittrex-enterprise/addresses'
12
+ require 'bittrex-enterprise/balances'
13
+ require 'bittrex-enterprise/currencies'
14
+ require 'bittrex-enterprise/deposits'
15
+ require 'bittrex-enterprise/markets'
16
+ require 'bittrex-enterprise/orders'
17
+ require 'bittrex-enterprise/ping'
18
+ require 'bittrex-enterprise/sub_accounts'
19
+ require 'bittrex-enterprise/transfers'
20
+ require 'bittrex-enterprise/withdrawals'
21
+
22
+ # Gem to use Bittrex API
23
+ module BittrexEnterprise
24
+
25
+ class << self
26
+ attr_accessor :configuration
27
+ end
28
+
29
+ def self.setup
30
+ @configuration ||= Configuration.new
31
+ yield(configuration)
32
+ puts configuration.inspect
33
+ end
34
+
35
+ # Handles the Bittrex API keys
36
+ class Configuration
37
+ attr_accessor :key, :secret
38
+ attr_reader :base_uri
39
+
40
+ def initialize
41
+ @key = ''
42
+ @secret = ''
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,68 @@
1
+ # Symbolizes all of hash's keys and subkeys.
2
+ # Also allows for custom pre-processing of keys (e.g. downcasing, etc)
3
+ # if the block is given:
4
+ #
5
+ # somehash.deep_symbolize { |key| key.downcase }
6
+ #
7
+ # Usage: either include it into global Hash class to make it available to
8
+ # to all hashes, or extend only your own hash objects with this
9
+ # module.
10
+ # E.g.:
11
+ # 1) class Hash; include DeepSymbolizable; end
12
+ # 2) myhash.extend DeepSymbolizable
13
+ #
14
+ # Source: https://github.com/ntamvl/poloniex_ruby/blob/master/lib/deep_symbolize.rb
15
+
16
+ # Used to symbolize hashes
17
+ module DeepSymbolizable
18
+ def deep_symbolize(&block)
19
+ method = self.class.to_s.downcase.to_sym
20
+ syms = DeepSymbolizable::Symbolizers
21
+ syms.respond_to?(method) ? syms.send(method, self, &block) : self
22
+ end
23
+
24
+ # Used to symbolize hashes
25
+ module Symbolizers
26
+ module_function
27
+
28
+ # the primary method - symbolizes keys of the given hash,
29
+ # preprocessing them with a block if one was given, and recursively
30
+ # going into all nested enumerables
31
+ def hash(hash, &block)
32
+ hash.each_with_object({}) do |(key, value), result|
33
+ # Recursively deep-symbolize subhashes
34
+ value = _recurse_(value, &block)
35
+
36
+ # Pre-process the key with a block if it was given
37
+ key = yield key if block_given?
38
+ # Symbolize the key string if it responds to to_sym
39
+ sym_key = begin
40
+ key.to_sym
41
+ rescue StandardError
42
+ key
43
+ end
44
+
45
+ # write it back into the result and return the updated hash
46
+ result[sym_key] = value
47
+ end
48
+ end
49
+
50
+ # walking over arrays and symbolizing all nested elements
51
+ def array(ary, &block)
52
+ ary.map { |v| _recurse_(v, &block) }
53
+ end
54
+
55
+ # handling recursion - any Enumerable elements (except String)
56
+ # is being extended with the module, and then symbolized
57
+ def _recurse_(value, &block)
58
+ if value.is_a?(Enumerable) && !value.is_a?(String)
59
+ # support for a use case without extended core Hash
60
+ unless value.class.include?(DeepSymbolizable)
61
+ value.extend DeepSymbolizable
62
+ end
63
+ value = value.deep_symbolize(&block)
64
+ end
65
+ value
66
+ end
67
+ end
68
+ end