Class: Cts::Mpx::Query

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQuery

Instiatiate a page and query, set return’s to false.



51
52
53
54
55
56
57
# File 'lib/cts/mpx/query.rb', line 51

def initialize
  @page = Driver::Page.new

  @return_entries = true
  @return_count = false
  @query = {}
end

Instance Attribute Details

#accountString

Returns account account context, can be id or name.

Returns:

  • (String)

    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

#endpointString

Returns endpoint of the service.

Returns:

  • (String)

    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_pathString

Returns any extra_path.

Returns:

  • (String)

    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

#fieldsString

Returns Fields to gather.

Returns:

  • (String)

    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

#idsArray

Returns Ids to search through.

Returns:

  • (Array)

    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

#pagePage

Returns Page of the search results.

Returns:

  • (Page)

    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

#queryHash

Returns Additional query to add.

Returns:

  • (Hash)

    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

#rangeString

Returns String range in the service shell style.

Returns:

  • (String)

    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_countBoolean

Returns should this query return count (generally, no).

Returns:

  • (Boolean)

    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_entriesBoolean

Returns should this query return entries.

Returns:

  • (Boolean)

    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

#serviceString

Returns service the query is for.

Returns:

  • (String)

    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

#sortString

Returns string to sort in the service shell style.

Returns:

  • (String)

    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

#attributesSymbol[]

List of attributes availble

Returns:

  • (Symbol[])


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

#entriesEntries

List of entries created from the page

Returns:

  • (Entries)

    populated Entries object



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

Parameters:

  • user (User) (defaults to: nil)

    user to make calls with

Returns:

  • (Self)


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.

Parameters:

  • include_entries (Boolean) (defaults to: true)

    include the entries array or not

Returns:

  • (Hash)


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