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

Adding documentation and object to 'create' function. #56

Merged
merged 15 commits into from Jul 5, 2017

Conversation

khardsonhurley
Copy link
Contributor

  • Removed 'foo_id' and replaced with foo:{} object.
  • Updated documentation.

README.rst Outdated

::

import pygerduty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be import pygerduty.v2 or the module won't be available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, will fix.

pygerduty/v2.py Outdated
@@ -57,6 +57,7 @@ def __init__(self, pagerduty, base_container=None):

self.pagerduty = pagerduty
self.base_container = base_container
self.type = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I added it and was going to use it but ended up not using it. I will remove.

pygerduty/v2.py Outdated
'id': kwarg_value,
'type': new_key
}
elif kwarg_key.endswith('_ids'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe if it ends in _ids it will be a list of ids ["ID1", "ID2"] that needs to be translated to a list of objects

[{"type": "sometype", "id": "ID1"}, ...]

This seems to be doing the same thing as _id

pygerduty/v2.py Outdated
'type': new_key
}
elif kwarg_key.endswith('_ids'):
new_key = kwarg_key[:-3]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need to go from foo_ids to foos. This will go from foo_ids to foo_. Additionally we should be able to reuse some of this logic for ids from id. Would you mind moving this two functions id_to_obj and ids_to_objs, the latter making use of the former, and adding tests to verify the translations?

pygerduty/v2.py Outdated
else:
new_kwargs[kwarg_key] = kwarg_value
data[self.sname] = new_kwargs

response = self.pagerduty.request("POST", path, data=_json_dumper(data), extra_headers=extra_headers)
return self.container(self, **response.get(self.sname, {}))

@staticmethod
def id_to_obj(key, value):
new_key = key[:-3]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmjosack I struggled with figuring out where to put the string slice. Originally I left it inside of the create function but found that hard to test. Putting it in both id_to_obj and ids_to_objs it caused the key to be sliced twice since ids_to_objs depends on id_to_obj. It created something like this:

[{'id': 'PF9KMXH', 'type': 'servi'}, {'id': 'PIJ90N7', 'type': 'servi'}]

My solution was to only do it in id_to_obj, but then I realized we check for '_ids' two times (here and in create function) and this did not see very dry. Is there a better way to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option is to only pass values to these functions and worry about renaming the key in the outer function that I suggested.

pygerduty/v2.py Outdated

for kwarg_key, kwarg_value in kwargs.iteritems():
if kwarg_key.endswith('_id'):
new_kwargs = Collection.id_to_obj(kwarg_key, kwarg_value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're overwriting new_kwargs here? Can you move this entire loop into a function and add a test for it to make sure we're not losing kwargs? The test should have kwargs that are and aren't transformed and test both id and ids types.

pygerduty/v2.py Outdated
def id_to_obj(key, value):
new_key = key[:-3]
if key.endswith('_ids'):
new_key = key[:-4] + "s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any resources that end in y that might be ies instead of s? e.g. policy_ids -> policies. I believe we have a pluralize function that could be reused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see anywhere where policy_ids are used in the API reference. The v1 reference actually shows:

  "escalation_rules": [
    {
      "id": "PYO9B13",
      "escalation_delay_in_minutes": 22,
      ...
       }
    }

compared to in v2:

{
  "escalation_policies": [
    {
      "id": "PANZZEQ",
      "type": "escalation_policy",
      ...
    }
}

pygerduty/v2.py Outdated
else:
new_kwargs[kwarg_key] = kwarg_value
data[self.sname] = new_kwargs

response = self.pagerduty.request("POST", path, data=_json_dumper(data), extra_headers=extra_headers)
return self.container(self, **response.get(self.sname, {}))

@staticmethod
def id_to_obj(key, value):
new_key = key[:-3]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One option is to only pass values to these functions and worry about renaming the key in the outer function that I suggested.


def test_id_to_obj():

kwarg = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these tabs for indents?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been having issues with my tabs, sometimes it does tabs = four spaces and other times it does not. I will check on it.

},
{
"id": "PIJ90N7",
"type": "services"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type should be service here I believe. It's the key to this list that needs to be plural that's passed to the api.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmjosack Actually I just looked back and this is the reference thing we talked about before:

"services": [
      {
        "id": "PIJ90N7",
        "type": "service_reference"
      }
    ],

You said that you think it won't mind right? I will go ahead and change it to service if you think that will work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, pretty sure it happily takes either service or service_reference but I believe it has to be singular.

Krishelle Hardson-Hurley added 2 commits June 30, 2017 16:48
- First one processes the kwargs and ensures that no kwargs are lost.
- Second one cuts off the suffix _id or _ids so that this method is testable.
"end_time": "2012-06-16T14:00:00-04:00Z",
"description": "Description goes here",
"service_ids": [
"PF9KMXH"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include more than one ID here to ensure it works with multiple?


new_kwargs = pygerduty.v2.Collection.process_kwargs(kwargs_1)

print new_kwargs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this print?


def test_process_kwargs():

kwargs_1 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a singular _id test in here as well to make sure everything works together?

- Added a singular _id test to ensure that the library can process _id into an object.
- Added another id to the list of service_ids to ensure it works with multiple id inputs.
- Cleaned up code.
@gmjosack gmjosack merged commit 92fb1b2 into dropbox:master Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants