Class: Cts::Mpx::Query
- Inherits:
-
Object
- Object
- Cts::Mpx::Query
- Includes:
- Creatable
- Defined in:
- lib/cts/mpx/query.rb
Overview
Query method, allows you to build and send a query to the data services.
Instance Attribute Summary collapse
-
#account ⇒ String
Account account context, can be id or name.
-
#endpoint ⇒ String
Endpoint of the service.
-
#extra_path ⇒ String
Any extra_path.
-
#fields ⇒ String
Fields to gather.
-
#ids ⇒ Array
Ids to search through.
-
#page ⇒ Page
Page of the search results.
-
#query ⇒ Hash
Additional query to add.
-
#range ⇒ String
String range in the service shell style.
-
#return_count ⇒ Boolean
Should this query return count (generally, no).
-
#return_entries ⇒ Boolean
Should this query return entries.
-
#service ⇒ String
Service the query is for.
-
#sort ⇒ String
String to sort in the service shell style.
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes ⇒ Symbol[]
List of attributes availble.
-
#entries ⇒ Entries
List of entries created from the page.
-
#initialize ⇒ Query
constructor
Instiatiate a page and query, set return’s to false.
-
#run(user: nil) ⇒ Self
Run the query.
- #save_results_to_file(filename) ⇒ Object
-
#to_h(include_entries: true) ⇒ Hash
Hash representation of the query data.
Constructor Details
Instance Attribute Details
#account ⇒ String
Returns account account context, can be id or name.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#endpoint ⇒ String
Returns endpoint of the service.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#extra_path ⇒ String
Returns any extra_path.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#fields ⇒ String
Returns Fields to gather.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#ids ⇒ Array
Returns Ids to search through.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#page ⇒ Page
Returns Page of the search results.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#query ⇒ Hash
Returns Additional query to add.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#range ⇒ String
Returns String range in the service shell style.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#return_count ⇒ Boolean
Returns should this query return count (generally, no).
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#return_entries ⇒ Boolean
Returns should this query return entries.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#service ⇒ String
Returns service the query is for.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
#sort ⇒ String
Returns string to sort in the service shell style.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cts/mpx/query.rb', line 28 class Query include Creatable attribute name: 'account_id', kind_of: String attribute name: 'endpoint', kind_of: String attribute name: 'extra_path', kind_of: String attribute name: 'fields', kind_of: String attribute name: 'ids', kind_of: Array attribute name: 'page', kind_of: Driver::Page attribute name: 'query', kind_of: Hash attribute name: 'range', kind_of: String attribute name: 'return_count' attribute name: 'return_entries' attribute name: 'service', kind_of: String attribute name: 'sort', kind_of: String # List of attributes availble # @return [Symbol[]] def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end # Instiatiate a page and query, set return's to false. def initialize @page = Driver::Page.new @return_entries = true @return_count = false @query = {} end # List of entries created from the page # @return [Entries] populated Entries object def entries @page.to_mpx_entries end # Run the query # @param [User] user user to make calls with # @return [Self] def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end # Hash representation of the query data. Has a key for params and for entries. # @param [Boolean] include_entries include the entries array or not # @return [Hash] def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end private # List of parameters that are currently set in the query # @return [Hash] def params output = {} attributes.each do |attribute| output.store attribute, instance_variable_get("@#{attribute}") unless instance_variable_get("@#{attribute}").nil? end output[:count] = output.delete :return_count unless output[:return_count].nil? output[:entries] = output.delete :return_entries unless output[:return_entries].nil? output end end |
Class Method Details
.load_results_from_file(filename) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/cts/mpx/query.rb', line 93 def self.load_results_from_file(filename) tmp_to_h = Oj.load File.read filename n = Query.create tmp_to_h[:params] n.page.entries = tmp_to_h[:entries][:entries] n.page.xmlns = tmp_to_h[:entries][:xmlns] n end |
Instance Method Details
#attributes ⇒ Symbol[]
List of attributes availble
46 47 48 |
# File 'lib/cts/mpx/query.rb', line 46 def attributes %i[account_id endpoint extra_path fields ids query range return_count return_entries service sort] end |
#entries ⇒ Entries
List of entries created from the page
61 62 63 |
# File 'lib/cts/mpx/query.rb', line 61 def entries @page.to_mpx_entries end |
#run(user: nil) ⇒ Self
Run the query
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cts/mpx/query.rb', line 68 def run(user: nil) Driver::Helpers.required_arguments %i[user], binding Driver::Exceptions.raise_unless_argument_error? user, User raise "service must be set" unless service raise "endpoint must be set" unless endpoint response = Services::Data.get params.merge(user: user) @page = response.page self end |
#save_results_to_file(filename) ⇒ Object
89 90 91 |
# File 'lib/cts/mpx/query.rb', line 89 def save_results_to_file(filename) File.write filename, Oj.dump(to_h) end |
#to_h(include_entries: true) ⇒ Hash
Hash representation of the query data. Has a key for params and for entries.
83 84 85 86 87 |
# File 'lib/cts/mpx/query.rb', line 83 def to_h(include_entries: true) h = { params: params } h[:entries] = entries.to_h if include_entries h end |