Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get Json response of the Object #12

Closed
tusharpatelgreenapex opened this issue Nov 14, 2019 · 4 comments
Closed

How to get Json response of the Object #12

tusharpatelgreenapex opened this issue Nov 14, 2019 · 4 comments

Comments

@tusharpatelgreenapex
Copy link

tusharpatelgreenapex commented Nov 14, 2019

How to get Json response of the Object

@mroloux
Copy link
Member

mroloux commented Nov 14, 2019

We're discussing this on Intercom

@mroloux mroloux closed this as completed Nov 14, 2019
@tusharpatelgreenapex
Copy link
Author

I have made changes to sdk for my solution. If you feel perfect please add this to the SDK to get appropriate DICT response which enable user to easily serialize the objects. Please update this as soon as possible. we need to integrate new sdk

`
class EventReportItem:
def init(self, item_data):
self.status = item_data.get("status")
self.label = item_data.get("label")
self.labels = item_data.get("labels")
self.category_label = item_data.get("categoryLabel")
self.category_key = item_data.get("categoryKey")
self.ticket_type = item_data.get("ticketType")
self.order_id = item_data.get("orderId")
self.for_sale = item_data.get("forSale")
self.hold_token = item_data.get("holdToken")
self.section = item_data.get("section")
self.entrance = item_data.get("entrance")
self.num_booked = item_data.get("numBooked")
self.num_free = item_data.get("numFree")
self.num_held = item_data.get("numHeld")
self.capacity = item_data.get("capacity")
self.object_type = item_data.get("objectType")
self.extra_data = item_data.get("extraData")

def to_json(self):
    return self.__dict__

class BestAvailableObjects:
def init(self, data):
self.next_to_each_other = data.get("nextToEachOther")
self.objects = data.get("objects")
self.objectDetails = {}
for key, value in iteritems(data.get("objectDetails")):
self.objectDetails[key] = EventReportItem(value).to_json()

def to_json(self):
    return self.__dict__`

@mroloux
Copy link
Member

mroloux commented Nov 15, 2019

Hi,

Correct me if I'm wrong, but I don't think we need to add to_json methods. You can convert to json like this:

from json import JSONEncoder

class MyEncoder(JSONEncoder):
    def default(self, o):
        return o.__dict__

best_available_objects_as_json = MyEncoder().encode(best_available_objects)

@mroloux mroloux reopened this Nov 15, 2019
@tusharpatelgreenapex
Copy link
Author

perfect thanks @mroloux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants