Class: GameMachine::DataStores::Gamecloud
- Inherits:
-
Object
- Object
- GameMachine::DataStores::Gamecloud
- Defined in:
- lib/game_machine/data_stores/gamecloud.rb
Instance Attribute Summary collapse
-
#serialization ⇒ Object
readonly
Returns the value of attribute serialization.
Instance Method Summary collapse
- #connect ⇒ Object
- #delete(id) ⇒ Object
- #delete_matching(query_string) ⇒ Object
- #get(id) ⇒ Object
- #handle_entity_response(response) ⇒ Object
- #handle_response(response) ⇒ Object
-
#initialize(serialization) ⇒ Gamecloud
constructor
A new instance of Gamecloud.
- #query(query, limit) ⇒ Object
- #set(id, value) ⇒ Object
Constructor Details
#initialize(serialization) ⇒ Gamecloud
Returns a new instance of Gamecloud.
6 7 8 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 6 def initialize(serialization) @serialization = serialization end |
Instance Attribute Details
#serialization ⇒ Object (readonly)
Returns the value of attribute serialization.
5 6 7 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 5 def serialization @serialization end |
Instance Method Details
#connect ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 10 def connect JavaLib::CloudClient.get_instance.set_credentials( Application.config.gamecloud.host, Application.config.gamecloud.user, Application.config.gamecloud.api_key ) end |
#delete(id) ⇒ Object
73 74 75 76 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 73 def delete(id) response = JavaLib::CloudClient.get_instance.delete(id) handle_response(response) end |
#delete_matching(query_string) ⇒ Object
78 79 80 81 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 78 def delete_matching(query_string) response = JavaLib::CloudClient.get_instance.delete_matching(query_string) handle_response(response) end |
#get(id) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 64 def get(id) if serialization == 'json' response = JavaLib::CloudClient.get_instance.getString(id) else response = JavaLib::CloudClient.get_instance.getBytes(id) end handle_entity_response(response) end |
#handle_entity_response(response) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 18 def handle_entity_response(response) if response.status == 200 serialization == 'json' ? response.stringBody : response.byteBody elsif response.status == 404 nil else raise "Gamecloud.get returned status: #{response.status}" end end |
#handle_response(response) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 28 def handle_response(response) if [200,204].include?(response.status) true elsif response.status == 404 false else raise "Gamecloud.get returned status: #{response.status}" end end |
#query(query, limit) ⇒ Object
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 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 38 def query(query,limit) response = JavaLib::CloudClient.get_instance.query(query,limit,serialization) if response.status == 200 query_response = MessageLib::CloudQueryResponse.parse_from(response.byteBody) if serialization == 'json' if query_response.getJsonMessageList.nil? = [] else = query_response.getJsonMessageList end else if query_response.getByteMessageList.nil? = [] else = query_response.getByteMessageList end end elsif response.status == 404 [] else raise "Gamecloud.get returned status: #{response.status}" end end |
#set(id, value) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/game_machine/data_stores/gamecloud.rb', line 83 def set(id,value) if serialization == 'json' response = JavaLib::CloudClient.get_instance.putString(id,value) else response = JavaLib::CloudClient.get_instance.putBytes(id,value) end handle_response(response) end |